Skip to content

Commit

Permalink
Merge pull request #3 from farmer00317558/main
Browse files Browse the repository at this point in the history
add darwin-arm64 prebuild & typescript definitions
  • Loading branch information
auxten authored Dec 23, 2023
2 parents efd223e + 2354574 commit 363f55e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
build
/metadata
/user_defined
9 changes: 5 additions & 4 deletions example.js
Original file line number Diff line number Diff line change
@@ -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);
22 changes: 22 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added prebuilds/darwin-arm64/node.napi.node
Binary file not shown.
31 changes: 25 additions & 6 deletions sessions.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 363f55e

Please sign in to comment.