@@ -14,48 +14,34 @@ Experimental [chDB](https://github.com/chdb-io/chdb) FFI bindings for the [bun r
14
14
15
15
#### Build binding
16
16
``` bash
17
- bun install chdb-bun
17
+ bun run build
18
+ bun run example.ts
18
19
```
19
20
20
21
#### Usage
21
22
22
- #### Query Constructor
23
- ``` js
24
- import { db } from ' chdb-bun' ;
25
-
26
- const conn = new db (' CSV' )
27
- console .log (conn .query (" SELECT version()" ));
28
- ```
29
-
30
- #### Query _ (query, * format)_
23
+ #### Query(query, * format) (ephemeral)
31
24
``` javascript
32
- import { db } from ' chdb-bun' ;
33
- const conn = new db (' CSV' )
25
+ import { query } from ' chdb-bun' ;
34
26
35
27
// Query (ephemeral)
36
- var result = conn . query (" SELECT version()" , " CSV" );
37
- console .log (result) // 23.10.1.1
28
+ var result = query (" SELECT version()" , " CSV" );
29
+ console .log (result); // 23.10.1.1
38
30
```
39
31
40
- #### Session _ (query, * format, * path) _
32
+ #### Session.Query (query, * format)
41
33
``` javascript
42
- import { db } from ' chdb-bun' ;
43
- const conn = new db ( ' CSV ' , ' / tmp' )
34
+ import { Session } from ' chdb-bun' ;
35
+ const sess = new Session ( ' ./chdb-bun- tmp' );
44
36
45
37
// Query Session (persistent)
46
- conn .session (" CREATE FUNCTION IF NOT EXISTS hello AS () -> 'chDB'" );
47
- result = conn .session (" SELECT hello()" , " CSV" );
48
- console .log (result)
49
- ```
38
+ sess .query (" CREATE FUNCTION IF NOT EXISTS hello AS () -> 'Hello chDB'" , " CSV" );
39
+ var result = sess .query (" SELECT hello()" , " CSV" );
40
+ console .log (result);
50
41
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 ();
42
+ // Before cleanup, you can find the database files in `./chdb-bun-tmp`
43
+
44
+ sess .cleanup (); // cleanup session, this will delete the database
59
45
```
60
46
61
47
<br >
0 commit comments