Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Prevents merge conflicts in Ottotime files
.ottotime merge=union
8 changes: 4 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
version: 2
updates:
- package-ecosystem: "npm"
- package-ecosystem: 'npm'
directories:
- "/"
- '/'
schedule:
interval: "daily"
interval: 'daily'
groups:
dependencies:
patterns:
- "*"
- '*'
30 changes: 0 additions & 30 deletions .github/workflows/ci.yml

This file was deleted.

43 changes: 43 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish to NPM
on:
release:
types: [published]

jobs:
build-and-publish:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: pnpm
- name: Install npm dependencies
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm eslint --max-warnings 0
- name: Format
run: pnpm prettier --check .
- name: Build
run: pnpm build
- name: Publint
run: pnpm publint
- name: Run Tests
run: pnpm test
- name: Test Example
run: |
cd example
pnpm i
pnpm example

- name: Publish
run: |
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
pnpm publish --no-git-checks
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'Test'
on:
pull_request:

jobs:
node-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: pnpm
- name: Install npm dependencies
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm eslint --max-warnings 0
- name: Format
run: pnpm prettier --check .
- name: Build
run: pnpm build
- name: Publint
run: pnpm publint
- name: Run Tests
run: pnpm test
- name: Test Example
run: |
cd example
pnpm i
pnpm example
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
node_modules
/lib-esm
/lib-cjs
/example/package-lock.json
*.tsbuildinfo
Session.vim
test.db
test.db
/dist
3 changes: 3 additions & 0 deletions .ottotime
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# OTTOTIME
# Do not edit manually. Check into git.
1744132356- 24:09
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm-lock.yaml
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"useTabs": true,
"trailingComma": "all"
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.6.0 -- 2025-02-06

- Update to @libsql/client 0.14.0

## 0.4.0 -- 2024-07-09

- Use @libsql/client instead of @libsql/hrana-client.
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
# kysely-libsql

A [Kysely][kysely] dialect for [libSQL][libsql], compatible with [@libsql/client][libsql-client-ts].
A [Kysely][kysely] dialect for [libSQL (Turso)][libsql], compatible with [@libsql/client][libsql-client-ts].

[kysely]: https://github.com/koskimas/kysely
[libsql]: https://github.com/tursodatabase/libsql

## Installation

```shell
npm install @libsql/kysely-libsql
pnpm i kysely-libsql
```

## Usage

Pass a `LibsqlDialect` instance as the `dialect` when creating the `Kysely` object:

```typescript
import { Kysely } from "kysely";
import { LibsqlDialect } from "@libsql/kysely-libsql";
import { Kysely } from 'kysely';
import { LibsqlDialect } from 'kysely-libsql';

interface Database {
...
}

const db = new Kysely<Database>({
dialect: new LibsqlDialect({
url: "libsql://localhost:8080?tls=0",
authToken: "<token>", // optional
url: 'libsql://localhost:8080?tls=0',
authToken: '<token>', // optional
}),
});
```

Instead of a `url`, you can also pass an existing `Client` from [`@libsql/client`][libsql-client-ts]:

```typescript
import { createClient } from "@libsql/client";
import { createClient } from '@libsql/client';

const client = createClient({
url: "libsql://localhost:8080",
url: 'libsql://localhost:8080',
});

const db = new Kysely<Database>({
dialect: new LibsqlDialect({ client }),
dialect: new LibsqlDialect({ client }),
});

// after you are done with the `db`, you must close the `client`:
Expand All @@ -61,4 +61,4 @@ This project is licensed under the MIT license.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in `@libsql/kysely-libsql` by you, shall be licensed as MIT, without any additional terms or conditions.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in `kysely-libsql` by you, shall be licensed as MIT, without any additional terms or conditions.
29 changes: 29 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import globals from 'globals';
import js from '@eslint/js';
import ts from 'typescript-eslint';

export default ts.config(
js.configs.recommended,
...ts.configs.recommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.es2017,
},
},
},
{
rules: {
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
},
},
{ ignores: ['dist/'] },
);
82 changes: 42 additions & 40 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
import { Kysely, Generated } from "kysely";
import { LibsqlDialect } from "@libsql/kysely-libsql";
import { Kysely, type Generated } from 'kysely';
import { LibsqlDialect } from 'kysely-libsql';

interface Database {
book: BookTable,
book: BookTable;
}

interface BookTable {
id: Generated<number>,
author: string,
title: string,
year: number | null,
id: Generated<number>;
author: string;
title: string;
year: number | null;
}

async function example() {
const db = new Kysely<Database>({
dialect: new LibsqlDialect({
url: "file:test.db",
}),
});

await db.schema
.createTable("book")
.addColumn("id", "integer", col => col.primaryKey())
.addColumn("author", "text", col => col.notNull())
.addColumn("title", "text", col => col.notNull())
.addColumn("year", "integer")
.execute();

await db
.insertInto("book")
.values([
{ author: "Jane Austen", title: "Sense and Sensibility", year: 1811 },
{ author: "Daniel Defoe", title: "Robinson Crusoe", year: 1719 },
{ author: "Sally Rooney", title: "Beautiful World, Where Are You?", year: 2021 },
])
.execute();

const books = await db
.selectFrom("book")
.selectAll()
.orderBy("year", "asc")
.execute();
for (const book of books) {
console.dir(book);
}

await db.destroy();
const db = new Kysely<Database>({
dialect: new LibsqlDialect({
url: 'file:test.db',
}),
});

await db.schema
.createTable('book')
.addColumn('id', 'integer', (col) => col.primaryKey())
.addColumn('author', 'text', (col) => col.notNull())
.addColumn('title', 'text', (col) => col.notNull())
.addColumn('year', 'integer')
.execute();

await db
.insertInto('book')
.values([
{ author: 'Jane Austen', title: 'Sense and Sensibility', year: 1811 },
{ author: 'Daniel Defoe', title: 'Robinson Crusoe', year: 1719 },
{
author: 'Sally Rooney',
title: 'Beautiful World, Where Are You?',
year: 2021,
},
])
.execute();

const books = await db
.selectFrom('book')
.selectAll()
.orderBy('year', 'asc')
.execute();
console.log(books);

await db.destroy();
}

example();
22 changes: 10 additions & 12 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"type": "commonjs",

"dependencies": {
"@libsql/kysely-libsql": ".."
},
"devDependencies": {
"ts-node": "^10.9.1"
},

"scripts": {
"example": "ts-node index.ts"
}
"dependencies": {
"kysely-libsql": "link:.."
},
"scripts": {
"example": "rm -f test.db && tsx index.ts"
},
"devDependencies": {
"@types/node": "^22.13.1",
"tsx": "^4.19.2"
}
}
Loading
Loading