From 2e1e28cfc917e1d8e11557e4dc83e5b750d38278 Mon Sep 17 00:00:00 2001 From: Ben Ashton Date: Tue, 16 Mar 2021 09:53:37 -0700 Subject: [PATCH] Added functioning PRAGMA support --- src/query_wrapper.mjs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/query_wrapper.mjs b/src/query_wrapper.mjs index 83edfaa..a6557b8 100644 --- a/src/query_wrapper.mjs +++ b/src/query_wrapper.mjs @@ -22,17 +22,41 @@ export class QueryWrapper { execute(db) { if (this.isAnyOf("INSERT", "UPDATE", "DELETE")) { return this.executeRun(db); + } else if (this.isAnyOf("PRAGMA")) { + return this.executeGet(db); } else { return this.executeAll(db); } } + executeGet(db) { + return new Promise((resolve, reject) => { + const self = this; + + log(this.sql); + db.get(this.sql, ...this.args, function (err, row) { + if (err) { + reject(NodeAdapterError.from(err)); + return; + } + + const result = {}; + + if (row) { + result.rows = [row]; + } + + resolve(ResponseWrapper.success(result)); + }); + }); + } + executeRun(db) { return new Promise((resolve, reject) => { const self = this; log(this.sql); - db.run(this.sql, ...this.args, function (err) { + db.get(this.sql, ...this.args, function (err) { if (err) { reject(NodeAdapterError.from(err)); return;