Skip to content

kysely-org/kysely-turso

Repository files navigation

A Kysely-branded yellow duck brainstorming startup ideas together with a the Turso creature thing.

NPM Version Tests License Issues Pull Requests GitHub contributors Downloads

Join the discussion ⠀⠀⠀⠀⠀⠀⠀

Discord Bluesky

kysely-turso offers Kysely dialects for Turso's serverless driver and LibSQL client.

Installation

Node.js

npm install kysely-turso @tursodatabase/serverless kysely
pnpm add kysely-turso @tursodatabase/serverless kysely
yarn add kysely-turso @tursodatabase/serverless kysely

Other runtimes

deno add npm:kysely-turso npm:@tursodatabase/serverless npm:kysely
bun add kysely-turso @tursodatabase/serverless kysely

Usage

@tursodatabase/serverless

Interactive transactions are not supported as of @tursodatabase/[email protected].

import { connect } from '@tursodatabase/serverless'
import { type GeneratedAlways, Kysely } from 'kysely'
import { TursoServerlessDialect } from 'kysely-turso/serverless'

interface Database {
	person: {
		id: GeneratedAlways<number>;
		first_name: string | null;
		last_name: string | null;
		age: number;
	};
}

const db = new Kysely<Dataabase>({
  dialect: new TursoServerlessDialect({
    connection: connect({ 
      authToken: process.env.TURSO_AUTH_TOKEN!,
      url: process.env.TURSO_URL!,
    }),
  }),
})

const people = await db.selectFrom("person").selectAll().execute();

@tursodatabase/serverless/compat

Signatures are defined, but nothing works as of @tursodatabase/[email protected].

import { createClient } from '@tursodatabase/serverless/compat'
import { type GeneratedAlways, Kysely } from 'kysely'
import { LibSQLialect } from 'kysely-turso/libsql'

interface Database {
	person: {
		id: GeneratedAlways<number>;
		first_name: string | null;
		last_name: string | null;
		age: number;
	};
}

const db = new Kysely<Dataabase>({
  dialect: new LibSQLDialect({
    client: createClient({ url: process.env.TURSO_URL! }),
  }),
})

const people = await db.selectFrom("person").selectAll().execute();

@libsql/client

import { createClient } from '@libsql/client'
import { type GeneratedAlways, Kysely } from 'kysely'
import { LibSQLialect } from 'kysely-turso/libsql'

interface Database {
	person: {
		id: GeneratedAlways<number>;
		first_name: string | null;
		last_name: string | null;
		age: number;
	};
}

const db = new Kysely<Dataabase>({
  dialect: new LibSQLDialect({
    client: createClient({ url: process.env.TURSO_URL! }),
  }),
})

const people = await db.selectFrom("person").selectAll().execute();

Contribution

Prerequisites

  1. Turso CLI

Acknowledgements

honzasp and penberg for creating and maintaining @libsql/kysely-libsql.

ottomated for maintaining the kysely-libsql fork. ❤️