22 <img src =" https://avatars.githubusercontent.com/u/132536224 " width =130 />
33</a >
44
5- [ ![ chDB-node ] ( https://github.com/metrico/chdb-bun/actions/workflows/bun-test.yml/badge.svg )] ( https://github.com/metrico/chdb-bun/actions/workflows/bun-test.yml )
5+ [ ![ chDB-bun ] ( https://github.com/metrico/chdb-bun/actions/workflows/bun-test.yml/badge.svg )] ( https://github.com/metrico/chdb-bun/actions/workflows/bun-test.yml )
66
77# chdb-bun <img src =" https://user-images.githubusercontent.com/1423657/236928733-43e4f74e-5cff-4b3f-8bb7-20df58e10829.png " height =20 />
88Experimental [ chDB] ( https://github.com/auxten/chdb ) FFI bindings for [ bun.sh] ( https://bun.sh )
@@ -18,18 +18,44 @@ bun install chdb-bun
1818```
1919
2020#### Usage
21+
22+ #### Query Constructor
2123``` js
22- import { db , chdb } from ' chdb-bun' ;
24+ import { db } from ' chdb-bun' ;
2325
2426const conn = new db (' CSV' )
25- var result;
27+ console .log (conn .query (" SELECT version()" ));
28+ ```
2629
27- // Test query
28- result = conn .query (" SELECT version()" );
29- console .log (result)
30+ #### Query _ (query, * format)_
31+ ``` javascript
32+ import { db } from ' chdb-bun' ;
33+ const conn = new db (' CSV' )
34+
35+ // Query (ephemeral)
36+ var result = conn .query (" SELECT version()" , " CSV" );
37+ console .log (result) // 23.10.1.1
38+ ```
39+
40+ #### Session _ (query, * format, * path)_
41+ ``` javascript
42+ import { db } from ' chdb-bun' ;
43+ const conn = new db (' CSV' , ' /tmp' )
3044
31- // Test session
45+ // Query Session (persistent)
3246conn .session (" CREATE FUNCTION IF NOT EXISTS hello AS () -> 'chDB'" );
3347result = conn .session (" SELECT hello()" , " CSV" );
3448console .log (result)
3549```
50+
51+ > ⚠️ Sessions persist table data to disk. You can specify ` path ` to implement auto-cleanup strategies:
52+ ``` javascript
53+ const temperment = require (" temperment" );
54+ const tmp = temperment .directory ();
55+ conn .session (" CREATE FUNCTION IF NOT EXISTS hello AS () -> 'chDB'" , " CSV" , tmp)
56+ var result = = chdb .Session (" SELECT hello();" )
57+ console .log (result) // chDB
58+ tmp .cleanup .sync ();
59+ ```
60+
61+ <br >
0 commit comments