forked from tursodatabase/kysely-libsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
53 lines (45 loc) · 1.07 KB
/
index.ts
File metadata and controls
53 lines (45 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Kysely, type Generated } from 'kysely';
import { LibsqlDialect } from 'kysely-libsql';
interface Database {
book: BookTable;
}
interface BookTable {
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();
console.log(books);
await db.destroy();
}
example();