Skip to content

Commit aca0484

Browse files
authored
Merge pull request #8 from dnsjm/main
feature/add supabase connection 3d
2 parents a53ee9c + 73a9f5a commit aca0484

4 files changed

Lines changed: 83 additions & 132 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "with-supabase",
3+
"version": "1.0.0",
4+
"description": "A simple example for using inquire with Supabase.",
5+
"private": true,
6+
"scripts": {
7+
"build": "tsc",
8+
"start": "ts-node ./src/index.ts"
9+
},
10+
"dependencies": {
11+
"@stackpress/inquire-pg": "0.3.27",
12+
"@supabase/supabase-js": "^2.42.0",
13+
"pg": "^8.13.1",
14+
"dotenv": "^16.4.5"
15+
},
16+
"devDependencies": {
17+
"@types/node": "22.9.3",
18+
"ts-node": "10.9.2",
19+
"typescript": "5.7.2"
20+
}
21+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2016",
4+
"module": "commonjs",
5+
"esModuleInterop": true,
6+
"forceConsistentCasingInFileNames": true,
7+
"strict": true,
8+
"skipLibCheck": true,
9+
"outDir": "dist",
10+
"sourceMap": true
11+
},
12+
"include": [
13+
"src/**/*"
14+
]
15+
}

gitignore.txt

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)