diff --git a/.gitignore b/.gitignore index dd87e2d..61e2846 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules build +/metadata +/user_defined \ No newline at end of file diff --git a/example.js b/example.js index 374f216..d4ee9c1 100644 --- a/example.js +++ b/example.js @@ -1,12 +1,13 @@ -const addon = require('.'); -const db = new addon.db('CSV') +const addon = require("."); +const db = new addon.db("CSV"); var result; // Test query result = db.query("SELECT version()"); -console.log(result) +console.log(result); // Test session db.session("CREATE FUNCTION IF NOT EXISTS hello AS () -> 'chDB'"); result = db.session("SELECT hello()", "TabSeparated"); -console.log(result) + +console.log(result); diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..54c931f --- /dev/null +++ b/index.d.ts @@ -0,0 +1,22 @@ +declare interface ChdbModule { + Execute(query: string, format: string): string; + Session(query: string, format: string, path: string): string; +} + +declare const chdb: ChdbModule; + +declare interface DB { + format: string; + path: string; + query(query: string, format?: string): string; + session(query: string, format?: string, path?: string): string; +} + +declare interface DBFactory { + (format?: string, path?: string): DB; + new (format?: string, path?: string): DB; +} + +declare const db: DBFactory; + +export { chdb, db }; diff --git a/index.js b/index.js index 8034e73..909168b 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,8 @@ -//const chdb = require('./build/chdb.node'); -const chdb = require('node-gyp-build')(__dirname) +const chdb = require("node-gyp-build")(__dirname); function db(format, path) { - - this.format = format || 'JSONCompact'; - this.path = path || '.'; + this.format = format || "JSONCompact"; + this.path = path || "."; // add properties to this this.query = (query, format) => chdb.Execute(query, format || this.format); diff --git a/package-lock.json b/package-lock.json index 09f13e3..c37bdcd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "chdb-node", - "version": "1.0.1", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "chdb-node", - "version": "1.0.1", + "version": "1.0.2", "hasInstallScript": true, "license": "AGPLv3", "dependencies": { diff --git a/prebuilds/darwin-arm64/node.napi.node b/prebuilds/darwin-arm64/node.napi.node new file mode 100755 index 0000000..08403e2 Binary files /dev/null and b/prebuilds/darwin-arm64/node.napi.node differ diff --git a/sessions.js b/sessions.js index ffe15cb..2c4f0ef 100644 --- a/sessions.js +++ b/sessions.js @@ -1,9 +1,28 @@ -const addon = require('.'); +const addon = require("."); var res; -addon.Session("CREATE DATABASE IF NOT EXISTS db_xxx Engine=Atomic;", "CSV", ".") -addon.Session("CREATE TABLE IF NOT EXISTS db_xxx.log_table_xxx (x String, y Int) ENGINE = Log;", "CSV", ".") -addon.Session("INSERT INTO db_xxx.log_table_xxx VALUES ('a', 1), ('b', 3), ('c', 2), ('d', 5);", "CSV", ".") -res = addon.Session("SELECT * FROM db_xxx.log_table_xxx LIMIT 4;", "Pretty", ".") -console.log(res); +addon.Session( + "CREATE DATABASE IF NOT EXISTS db_xxx Engine=Atomic;", + "CSV", + "." +); + +addon.Session( + "CREATE TABLE IF NOT EXISTS db_xxx.log_table_xxx (x String, y Int) ENGINE = Log;", + "CSV", + "." +); + +addon.Session( + "INSERT INTO db_xxx.log_table_xxx VALUES ('a', 1), ('b', 3), ('c', 2), ('d', 5);", + "CSV", + "." +); +res = addon.Session( + "SELECT * FROM db_xxx.log_table_xxx LIMIT 4;", + "Pretty", + "." +); + +console.log(res);