forked from stackpress/inquire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
47 lines (37 loc) · 1.21 KB
/
index.ts
File metadata and controls
47 lines (37 loc) · 1.21 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
import { Pool } from 'pg';
import connect from '@stackpress/inquire-pg';
import * as dotenv from 'dotenv';
dotenv.config();
async function main() {
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_KEY;
if (!supabaseUrl || !supabaseKey) {
throw new Error('Supabase URL and Key must be defined in .env');
}
const connectionString = `${supabaseUrl}`;
const pool = new Pool({
connectionString: supabaseUrl,
ssl: {
rejectUnauthorized: false,
},
application_name: "Inquire",
});
const connection = await pool.connect();
const engine = connect(connection);
const create = engine.create('profile')
.addField('id', { type: 'VARCHAR', length: 255 })
.addField('name', { type: 'VARCHAR', length: 255 })
.addPrimaryKey('id');
console.log(create.query());
console.log(await create);
const insert = engine
.insert('profile')
.values({ id: '1', name: 'John Doe' });
console.log(insert.query());
console.log(JSON.stringify(await insert, null, 2));
const select = engine.select('*').from('profile');
console.log(select.query());
console.log(JSON.stringify(await select, null, 2));
connection.release();
}
main().catch(console.error);