File tree 9 files changed +822
-9
lines changed
9 files changed +822
-9
lines changed Original file line number Diff line number Diff line change
1
+ import { text , integer , sqliteTable } from 'drizzle-orm/sqlite-core'
2
+ import { sql } from 'drizzle-orm'
3
+
4
+ export const Specs = sqliteTable ( 'Specs' , {
5
+ id : integer ( 'id' ) . primaryKey ( ) ,
6
+ parentId : integer ( 'parent_id' ) ,
7
+ content : text ( 'content' ) . notNull ( ) ,
8
+ createdAt : text ( 'created_at' )
9
+ . notNull ( )
10
+ . default ( sql `CURRENT_TIMESTAMP` ) ,
11
+ } )
Original file line number Diff line number Diff line change
1
+ import { defineConfig } from 'drizzle-kit'
2
+
3
+ export default defineConfig ( {
4
+ schema : './db/schema.ts' ,
5
+ driver : 'd1' ,
6
+ verbose : true ,
7
+ strict : true ,
8
+ out : './migrations' ,
9
+ } )
Original file line number Diff line number Diff line change
1
+ import { drizzle } from 'drizzle-orm/d1'
2
+ import { Specs } from '../../db/schema'
3
+
1
4
export interface Env {
2
5
// If you set another name in wrangler.toml as the value for 'binding',
3
6
// replace "DB" with the variable name you defined.
4
7
DB : D1Database
5
8
}
6
9
7
10
export async function onRequest ( context ) {
8
- // If you did not use `DB` as your binding name, change it here
9
- const { results } = await context . env . DB . prepare (
10
- 'SELECT * FROM Customers WHERE CompanyName = ?' ,
11
- )
12
- . bind ( 'Bs Beverages' )
13
- . all ( )
14
-
15
- return Response . json ( results )
11
+ const db = drizzle ( context . env . DB )
12
+
13
+ // Create a new entry
14
+ if ( context . request . method === 'POST' ) {
15
+ // TODO: Validation
16
+ const data = await context . request . json ( )
17
+
18
+ const result = await db
19
+ . insert ( Specs )
20
+ . values ( {
21
+ content : data . content ,
22
+ } )
23
+ . returning ( )
24
+
25
+ return Response . json ( result )
26
+ }
27
+
28
+ return new Response ( 'Method not allowed, try POST.' , {
29
+ status : 405 ,
30
+ } )
31
+
32
+ // const result = await db.select().from(Specs).all()
33
+
16
34
// console.log('json', await context.request.json())
17
35
18
36
// const data = {
Original file line number Diff line number Diff line change
1
+ {
2
+ "version" : " 5" ,
3
+ "dialect" : " sqlite" ,
4
+ "id" : " 88ea7ba3-9671-4d8a-b3cb-7672e6efeec5" ,
5
+ "prevId" : " 00000000-0000-0000-0000-000000000000" ,
6
+ "tables" : {
7
+ "Specs" : {
8
+ "name" : " Specs" ,
9
+ "columns" : {
10
+ "id" : {
11
+ "name" : " id" ,
12
+ "type" : " integer" ,
13
+ "primaryKey" : true ,
14
+ "notNull" : true ,
15
+ "autoincrement" : false
16
+ },
17
+ "parent_id" : {
18
+ "name" : " parent_id" ,
19
+ "type" : " integer" ,
20
+ "primaryKey" : false ,
21
+ "notNull" : false ,
22
+ "autoincrement" : false
23
+ },
24
+ "content" : {
25
+ "name" : " content" ,
26
+ "type" : " text" ,
27
+ "primaryKey" : false ,
28
+ "notNull" : true ,
29
+ "autoincrement" : false
30
+ },
31
+ "created_at" : {
32
+ "name" : " created_at" ,
33
+ "type" : " text" ,
34
+ "primaryKey" : false ,
35
+ "notNull" : true ,
36
+ "autoincrement" : false ,
37
+ "default" : " DATETIME('now')"
38
+ }
39
+ },
40
+ "indexes" : {},
41
+ "foreignKeys" : {},
42
+ "compositePrimaryKeys" : {},
43
+ "uniqueConstraints" : {}
44
+ }
45
+ },
46
+ "enums" : {},
47
+ "_meta" : {
48
+ "schemas" : {},
49
+ "tables" : {},
50
+ "columns" : {}
51
+ }
52
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "version" : " 5" ,
3
+ "dialect" : " sqlite" ,
4
+ "id" : " 74278783-0df3-42f9-88c5-434d63d7f212" ,
5
+ "prevId" : " 88ea7ba3-9671-4d8a-b3cb-7672e6efeec5" ,
6
+ "tables" : {
7
+ "Specs" : {
8
+ "name" : " Specs" ,
9
+ "columns" : {
10
+ "id" : {
11
+ "name" : " id" ,
12
+ "type" : " integer" ,
13
+ "primaryKey" : true ,
14
+ "notNull" : true ,
15
+ "autoincrement" : false
16
+ },
17
+ "parent_id" : {
18
+ "name" : " parent_id" ,
19
+ "type" : " integer" ,
20
+ "primaryKey" : false ,
21
+ "notNull" : false ,
22
+ "autoincrement" : false
23
+ },
24
+ "content" : {
25
+ "name" : " content" ,
26
+ "type" : " text" ,
27
+ "primaryKey" : false ,
28
+ "notNull" : true ,
29
+ "autoincrement" : false
30
+ }
31
+ },
32
+ "indexes" : {},
33
+ "foreignKeys" : {},
34
+ "compositePrimaryKeys" : {},
35
+ "uniqueConstraints" : {}
36
+ }
37
+ },
38
+ "enums" : {},
39
+ "_meta" : {
40
+ "schemas" : {},
41
+ "tables" : {},
42
+ "columns" : {}
43
+ }
44
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "version" : " 5" ,
3
+ "dialect" : " sqlite" ,
4
+ "id" : " 9605af17-a1b9-4179-adb3-d05af5e0fc04" ,
5
+ "prevId" : " 74278783-0df3-42f9-88c5-434d63d7f212" ,
6
+ "tables" : {
7
+ "Specs" : {
8
+ "name" : " Specs" ,
9
+ "columns" : {
10
+ "id" : {
11
+ "name" : " id" ,
12
+ "type" : " integer" ,
13
+ "primaryKey" : true ,
14
+ "notNull" : true ,
15
+ "autoincrement" : false
16
+ },
17
+ "parent_id" : {
18
+ "name" : " parent_id" ,
19
+ "type" : " integer" ,
20
+ "primaryKey" : false ,
21
+ "notNull" : false ,
22
+ "autoincrement" : false
23
+ },
24
+ "content" : {
25
+ "name" : " content" ,
26
+ "type" : " text" ,
27
+ "primaryKey" : false ,
28
+ "notNull" : true ,
29
+ "autoincrement" : false
30
+ },
31
+ "created_at" : {
32
+ "name" : " created_at" ,
33
+ "type" : " text" ,
34
+ "primaryKey" : false ,
35
+ "notNull" : true ,
36
+ "autoincrement" : false ,
37
+ "default" : " CURRENT_TIMESTAMP"
38
+ }
39
+ },
40
+ "indexes" : {},
41
+ "foreignKeys" : {},
42
+ "compositePrimaryKeys" : {},
43
+ "uniqueConstraints" : {}
44
+ }
45
+ },
46
+ "enums" : {},
47
+ "_meta" : {
48
+ "schemas" : {},
49
+ "tables" : {},
50
+ "columns" : {}
51
+ }
52
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "version" : " 5" ,
3
+ "dialect" : " sqlite" ,
4
+ "entries" : [
5
+ {
6
+ "idx" : 0 ,
7
+ "version" : " 5" ,
8
+ "when" : 1705278292306 ,
9
+ "tag" : " 0000_dizzy_living_lightning" ,
10
+ "breakpoints" : true
11
+ },
12
+ {
13
+ "idx" : 1 ,
14
+ "version" : " 5" ,
15
+ "when" : 1705278416497 ,
16
+ "tag" : " 0001_windy_dark_beast" ,
17
+ "breakpoints" : true
18
+ },
19
+ {
20
+ "idx" : 2 ,
21
+ "version" : " 5" ,
22
+ "when" : 1705278468137 ,
23
+ "tag" : " 0002_fast_amphibian" ,
24
+ "breakpoints" : true
25
+ }
26
+ ]
27
+ }
Original file line number Diff line number Diff line change 8
8
"build" : " vue-tsc && vite build" ,
9
9
"frontend" : " vite" ,
10
10
"backend" : " wrangler pages dev ./" ,
11
- "preview" : " vite preview"
11
+ "preview" : " vite preview" ,
12
+ "db:generate" : " drizzle-kit generate:sqlite --schema=./db/schema.ts --out=./migrations" ,
13
+ "db:up" : " drizzle-kit up:sqlite"
12
14
},
13
15
"dependencies" : {
14
16
"@scalar/api-reference" : " ^1.12.1" ,
17
+ "drizzle-orm" : " ^0.29.3" ,
15
18
"monaco-editor" : " ^0.45.0" ,
16
19
"vue" : " ^3.3.11"
17
20
},
18
21
"devDependencies" : {
19
22
"@vitejs/plugin-vue" : " ^4.5.2" ,
20
23
"concurrently" : " ^8.2.2" ,
24
+ "drizzle-kit" : " ^0.20.12" ,
21
25
"eslint" : " ^8.56.0" ,
22
26
"eslint-config-prettier" : " ^9.1.0" ,
23
27
"eslint-plugin-prettier-vue" : " ^5.0.0" ,
You can’t perform that action at this time.
0 commit comments