-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathdb.ts
50 lines (44 loc) · 1.27 KB
/
db.ts
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
import { sqliteTable, integer, text } from 'drizzle-orm/sqlite-core'
export default defineEventHandler(async () => {
const db0 = useDatabase()
const _tables = await db0.sql`
SELECT
name,
type
FROM
sqlite_schema
WHERE
type = 'table' AND
name NOT LIKE 'sqlite_%' and name NOT LIKE '_litestream_%' and name NOT LIKE '__drizzle%'
;`
console.log(_tables.rows)
const db = useDrizzle()
const tables = await db.all(sql`
SELECT
name,
type
FROM
sqlite_schema
WHERE
type = 'table' AND
name NOT LIKE 'sqlite_%' and name NOT LIKE '_litestream_%' and name NOT LIKE '__drizzle%'
;
`)
const todos = sqliteTable('todos', {
id: integer('id').primaryKey(),
text: text('text')
})
// const inserted = await db.insert(todos).values({ text: 'hello' }).returning().get()
// const todo = await db.select().from(todos).where(eq(todos.id, inserted.id)).get()
// const updated = await db.update(todos).set({ text: 'Bonjour' }).where(eq(todos.id, inserted.id)).returning()
const all = await db.select().from(todos).limit(3)
// const deleted = await db.delete(todos).where(eq(todos.id, all[0].id))
return {
tables,
// todo,
// inserted,
// updated,
// deleted,
all
}
})