Skip to content

Commit 363f55e

Browse files
authored
Merge pull request #3 from farmer00317558/main
add darwin-arm64 prebuild & typescript definitions
2 parents efd223e + 2354574 commit 363f55e

File tree

7 files changed

+59
-17
lines changed

7 files changed

+59
-17
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
build
3+
/metadata
4+
/user_defined

example.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
const addon = require('.');
2-
const db = new addon.db('CSV')
1+
const addon = require(".");
2+
const db = new addon.db("CSV");
33
var result;
44

55
// Test query
66
result = db.query("SELECT version()");
7-
console.log(result)
7+
console.log(result);
88

99
// Test session
1010
db.session("CREATE FUNCTION IF NOT EXISTS hello AS () -> 'chDB'");
1111
result = db.session("SELECT hello()", "TabSeparated");
12-
console.log(result)
12+
13+
console.log(result);

index.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
declare interface ChdbModule {
2+
Execute(query: string, format: string): string;
3+
Session(query: string, format: string, path: string): string;
4+
}
5+
6+
declare const chdb: ChdbModule;
7+
8+
declare interface DB {
9+
format: string;
10+
path: string;
11+
query(query: string, format?: string): string;
12+
session(query: string, format?: string, path?: string): string;
13+
}
14+
15+
declare interface DBFactory {
16+
(format?: string, path?: string): DB;
17+
new (format?: string, path?: string): DB;
18+
}
19+
20+
declare const db: DBFactory;
21+
22+
export { chdb, db };

index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
//const chdb = require('./build/chdb.node');
2-
const chdb = require('node-gyp-build')(__dirname)
1+
const chdb = require("node-gyp-build")(__dirname);
32

43
function db(format, path) {
5-
6-
this.format = format || 'JSONCompact';
7-
this.path = path || '.';
4+
this.format = format || "JSONCompact";
5+
this.path = path || ".";
86

97
// add properties to this
108
this.query = (query, format) => chdb.Execute(query, format || this.format);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prebuilds/darwin-arm64/node.napi.node

54.9 KB
Binary file not shown.

sessions.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1-
const addon = require('.');
1+
const addon = require(".");
22
var res;
33

4-
addon.Session("CREATE DATABASE IF NOT EXISTS db_xxx Engine=Atomic;", "CSV", ".")
5-
addon.Session("CREATE TABLE IF NOT EXISTS db_xxx.log_table_xxx (x String, y Int) ENGINE = Log;", "CSV", ".")
6-
addon.Session("INSERT INTO db_xxx.log_table_xxx VALUES ('a', 1), ('b', 3), ('c', 2), ('d', 5);", "CSV", ".")
7-
res = addon.Session("SELECT * FROM db_xxx.log_table_xxx LIMIT 4;", "Pretty", ".")
8-
console.log(res);
4+
addon.Session(
5+
"CREATE DATABASE IF NOT EXISTS db_xxx Engine=Atomic;",
6+
"CSV",
7+
"."
8+
);
9+
10+
addon.Session(
11+
"CREATE TABLE IF NOT EXISTS db_xxx.log_table_xxx (x String, y Int) ENGINE = Log;",
12+
"CSV",
13+
"."
14+
);
15+
16+
addon.Session(
17+
"INSERT INTO db_xxx.log_table_xxx VALUES ('a', 1), ('b', 3), ('c', 2), ('d', 5);",
18+
"CSV",
19+
"."
20+
);
921

22+
res = addon.Session(
23+
"SELECT * FROM db_xxx.log_table_xxx LIMIT 4;",
24+
"Pretty",
25+
"."
26+
);
27+
28+
console.log(res);

0 commit comments

Comments
 (0)