From bafce924f165ed77c9929a073bded3874808949e Mon Sep 17 00:00:00 2001 From: Tristen Harr Date: Sat, 19 Oct 2024 19:48:12 -0500 Subject: [PATCH 1/2] update --- duck.db | Bin 0 -> 12288 bytes duck.db.wal | Bin 0 -> 23899 bytes src/duckduckapi.ts | 9 +++++---- src/handlers/query.ts | 7 +++---- src/index.ts | 14 +++++++++----- 5 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 duck.db create mode 100644 duck.db.wal diff --git a/duck.db b/duck.db new file mode 100644 index 0000000000000000000000000000000000000000..b4d7caf8df3aaa33824dcf48c90929c84aead8e8 GIT binary patch literal 12288 zcmeI#u?fOZ5CG6G7;pt~0juz1p{5ffHmRK;-~x(kIE#ftI7D!iSV$0rfDjM@@2cbe z!5#0aKfUj_r`3G4I~3(6{1%rijcM%e&5rqc8Dq7mx_i73AV7cs0RjXF5FkK+009F3 z6G-aE?L50a+lkFrwDl0i?{xC1$OsT1K!5-N0t5&UAV7csfnf;v{}1C%wj@A+009C7 O2oNAZfB*pkeFR>}0WdTG literal 0 HcmV?d00001 diff --git a/duck.db.wal b/duck.db.wal new file mode 100644 index 0000000000000000000000000000000000000000..a08afc3f309784699ff62877c0b907447ec2656e GIT binary patch literal 23899 zcmeI4T}V@57{}j@nU?EDBvA;OH$jv+U49gj5M6W;yQ_;_q@J^yx|ObFN{R_WMmHs7 z5$qz$5fvEp&2ECo>>`9X6kb#pMp!8k_5p>bcXLqN8*hj491hI?kg*+<_s6sM`M=Nk zKaW#bi^}Y}zLzaM>^H(ij|Xao6lPPIE&1$FBCYLy<_IgnU41DqATK>cv#!>lm5`@3Dkm?p~Z$tK|SZS26*%PyrwdkOjzsYYQU}y)#?oY1k&FVGUIp9(eQV zWxVa49H3nUsHFnf=9>KMx^zbl&>;fUQ2~4@ET20ctC9l*MSyxD0Ijt5MKAN5kpqMT z05?@VpiMPx9E}u>%K;9H095sWc73d1e7g8QAHfk3fT|wQT87n|-foXP0-YiNRXw0J zjPyT`e}5nc=n?^_>H%%x>%Nb!g41$VMsE#oT3dedha8|+1fWtv+?+a5mZL03S&p*Y+_HRT_mg0B z12-Q9pYWdsBg{>H<{5HVVQ#`%!x4@n97p)FKf-Y{gPR#Aln_d|?3EBb2J{$A?lIto zmQV0tTIa6_ka^OW*0FqA2Q@^F*AS3z$ai`KAm3EO6;5;I8>ySVajB*OoMY{Uyu%O+|Dnl{iI%k{=w!ycKFP39nK z*+dO`V;}-Kt~UlEfJp^>mlYa>Xb_s)AjA=lBRo9<#@s~%2N;g<96!RL9qE~a&IGi> NSWnM@dYYjfzX9tYJ&phX literal 0 HcmV?d00001 diff --git a/src/duckduckapi.ts b/src/duckduckapi.ts index fc3ac48..4df3c1f 100644 --- a/src/duckduckapi.ts +++ b/src/duckduckapi.ts @@ -68,8 +68,9 @@ const connector: Connector = { * @param metrics */ tryInitState(_: Configuration, __: unknown): Promise { - const credentials: CredentialSchema = { url: DUCKDB_URL }; - const client = new duckdb.Database(credentials.url, DUCKDB_CONFIG); + // const credentials: CredentialSchema = { url: DUCKDB_URL }; + // const client = new duckdb.Database(credentials.url, DUCKDB_CONFIG); + const client = db; return Promise.resolve({ client: client }); }, @@ -207,7 +208,7 @@ async function createDuckDBFile(schema: string): Promise { export interface duckduckapi { dbSchema: string - loaderJob(): void; + loaderJob(db: duckdb.Database): void; getFunctions(): void; } @@ -218,6 +219,6 @@ export async function makeConnector(dda: duckduckapi): Promise { @@ -443,6 +442,7 @@ export async function plan_queries( async function do_all(con: any, query: SQLQuery): Promise { return new Promise((resolve, reject) => { + con.all(query.sql, ...query.args, function (err: any, res: any) { if (err) { reject(err); @@ -464,6 +464,7 @@ async function perform_query( const row_set = JSON.parse(res[0]["data"] as string) as RowSet; response.push(row_set); } + con.close(); return response; } @@ -483,8 +484,6 @@ export async function do_query( state: State, query: QueryRequest ): Promise { - console.log(query); - if (is_query_function(query, configuration)) { return await perform_query_function(state, query); } else { diff --git a/src/index.ts b/src/index.ts index 17def62..37b586a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,12 @@ import {start} from "@hasura/ndc-sdk-typescript"; import { makeConnector, duckduckapi, db} from "./duckduckapi"; - +import * as duckdb from "duckdb"; // get any api credentials from env vars const calendar: duckduckapi = { + // DROP TABLE IF EXISTS users; dbSchema: ` + DROP TABLE IF EXISTS users; CREATE TABLE IF NOT EXISTS users (id int, name string); `, @@ -13,19 +15,21 @@ const calendar: duckduckapi = { // Implementation for retrieving functions }, - loaderJob: () => { + loaderJob: (db: duckdb.Database) => { console.log("Running loader job..."); - async function insertLoop() { let id = 100; while (true) { + const con = db.connect(); // Insert a row into the table - await db.all(` + con.exec('BEGIN TRANSACTION'); + con.all(` INSERT INTO users (id, name) values (?, ?); `, id, 'name'+id.toString(), (err)=>{console.log(err)}); + con.run('COMMIT'); id++; console.log(`Inserted row ${id}`); - + con.close(); // Wait for 1 second before the next insertion await new Promise(resolve => setTimeout(resolve, 1000)); } From 9adc3f318268a0861ae8ed7a08ffb0956b2225a3 Mon Sep 17 00:00:00 2001 From: Tristen Harr Date: Sat, 19 Oct 2024 19:52:14 -0500 Subject: [PATCH 2/2] update to not drop table --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 37b586a..5958bd9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,6 @@ import * as duckdb from "duckdb"; const calendar: duckduckapi = { // DROP TABLE IF EXISTS users; dbSchema: ` - DROP TABLE IF EXISTS users; CREATE TABLE IF NOT EXISTS users (id int, name string); `,