File tree Expand file tree Collapse file tree 1 file changed +19
-12
lines changed Expand file tree Collapse file tree 1 file changed +19
-12
lines changed Original file line number Diff line number Diff line change 1
1
// 1
2
- import { PrismaClient } from '@prisma/client' ;
2
+ import { drizzle } from 'drizzle-orm/node-postgres' ;
3
+ import { migrate } from 'drizzle-orm/postgres-js/migrator' ;
4
+ import pg from 'pg' ;
5
+ import { links } from './drizzle/schema.js' ;
3
6
4
7
// 2
5
- const prisma = new PrismaClient ( ) ;
8
+ const client = new pg . Client ( process . env [ 'PG_CONNECTION_STRING' ] ) ;
6
9
7
- // 3
8
10
async function main ( ) {
9
- await prisma . link . create ( {
10
- data : {
11
- description : 'Fullstack tutorial for GraphQL' ,
12
- url : 'www.howtographql.com' ,
13
- } ,
11
+ // 3
12
+ await client . connect ( ) ;
13
+ const db = drizzle ( client ) ;
14
+ await migrate ( db , { migrationsFolder : './drizzle' } ) ;
15
+
16
+ // 4
17
+ await db . insert ( links ) . values ( {
18
+ description : 'Fullstack tutorial for GraphQL' ,
19
+ url : 'www.howtographql.com' ,
14
20
} ) ;
15
- const allLinks = await prisma . link . findMany ( ) ;
21
+
22
+ const allLinks = await db . select ( ) . from ( links ) ;
16
23
console . log ( allLinks ) ;
17
24
}
18
25
19
- // 4
26
+ // 5
20
27
main ( )
21
- // 5
28
+ // 6
22
29
. finally ( async ( ) => {
23
- await prisma . $disconnect ( ) ;
30
+ await client . end ( ) ;
24
31
} ) ;
You can’t perform that action at this time.
0 commit comments