1+ import { Pool } from 'pg' ;
2+ import connect from '@stackpress/inquire-pg' ;
3+ import * as dotenv from 'dotenv' ;
4+ dotenv . config ( ) ;
5+
6+ async function main ( ) {
7+ const supabaseUrl = process . env . SUPABASE_URL ;
8+ const supabaseKey = process . env . SUPABASE_KEY ;
9+
10+ if ( ! supabaseUrl || ! supabaseKey ) {
11+ throw new Error ( 'Supabase URL and Key must be defined in .env' ) ;
12+ }
13+
14+ const connectionString = `${ supabaseUrl } ` ;
15+
16+ const pool = new Pool ( {
17+ connectionString : supabaseUrl ,
18+ ssl : {
19+ rejectUnauthorized : false ,
20+ } ,
21+ application_name : "Inquire" ,
22+ } ) ;
23+
24+ const connection = await pool . connect ( ) ;
25+ const engine = connect ( connection ) ;
26+
27+ const create = engine . create ( 'profile' )
28+ . addField ( 'id' , { type : 'VARCHAR' , length : 255 } )
29+ . addField ( 'name' , { type : 'VARCHAR' , length : 255 } )
30+ . addPrimaryKey ( 'id' ) ;
31+ console . log ( create . query ( ) ) ;
32+ console . log ( await create ) ;
33+
34+ const insert = engine
35+ . insert ( 'profile' )
36+ . values ( { id : '1' , name : 'John Doe' } ) ;
37+ console . log ( insert . query ( ) ) ;
38+ console . log ( JSON . stringify ( await insert , null , 2 ) ) ;
39+
40+ const select = engine . select ( '*' ) . from ( 'profile' ) ;
41+ console . log ( select . query ( ) ) ;
42+ console . log ( JSON . stringify ( await select , null , 2 ) ) ;
43+
44+ connection . release ( ) ;
45+ }
46+
47+ main ( ) . catch ( console . error ) ;
0 commit comments