File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ CREATE DATABASE taskdb ;
Original file line number Diff line number Diff line change
1
+ CREATE TABLE IF NOT EXISTS tasks (
2
+ id SERIAL PRIMARY KEY ,
3
+ name VARCHAR (255 ) NOT NULL ,
4
+ etag INT NOT NULL DEFAULT 0
5
+ );
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console */
3
+ import { pgconfig } from '@/config.js' ;
4
+ import { readFile } from 'fs/promises' ;
5
+ import pg from 'pg' ;
6
+ export async function runSQLFile ( filePath : string ) {
7
+ const config = pgconfig ( process . env ) ;
8
+ const client = new pg . Client ( config ) ;
9
+
10
+ try {
11
+ await client . connect ( ) ;
12
+ const sql = await readFile ( filePath , { encoding : 'utf8' } ) ;
13
+ await client . query ( sql ) ;
14
+ console . log ( `Executed SQL file: ${ filePath } ` ) ;
15
+ } catch ( err ) {
16
+ console . error ( `Error executing SQL file ${ filePath } :` , err ) ;
17
+ } finally {
18
+ await client . end ( ) ;
19
+ }
20
+ }
21
+
22
+ await runSQLFile ( process . argv [ 2 ] ) ;
You can’t perform that action at this time.
0 commit comments