File tree Expand file tree Collapse file tree 5 files changed +51
-7
lines changed Expand file tree Collapse file tree 5 files changed +51
-7
lines changed Original file line number Diff line number Diff line change 16
16
17
17
<br >
18
18
19
- ### Example
20
- #### Query _ (query, format)_
19
+ ### Examples
20
+
21
+ #### Query Constructor
21
22
``` javascript
23
+ const addon = require (' .' );
22
24
const chdb = require (' chdb-node' );
25
+ const db = new chdb.db (' CSV' )
26
+ var result;
27
+
28
+ // Query (ephemeral)
29
+ result = db .query (" SELECT version()" , " TabSeparated" );
30
+ console .log (result)
31
+
32
+ // Query Session (persistent)
33
+ db .session (" CREATE FUNCTION IF NOT EXISTS hello AS () -> 'chDB'" );
34
+ result = db .session (" SELECT hello()" , " TabSeparated" );
35
+ console .log (result)
36
+ ```
37
+
38
+ #### Query _ (query, format)_
39
+ ``` javascript
40
+ const chdb = require (' chdb-node' ).chdb ;
23
41
var result = chdb .Execute (' SELECT version()' , ' CSV' );
24
42
console .log (result) // 23.6.1.1
25
43
```
26
44
27
45
#### Session _ (query, * format, * path)_
28
46
``` javascript
29
- const chdb = require (' chdb-node' );
47
+ const chdb = require (' chdb-node' ). chdb ;
30
48
chdb .Session (" CREATE FUNCTION IF NOT EXISTS hello AS () -> 'chDB'" )
31
49
var result = = chdb .Session (" SELECT hello();" )
32
50
console .log (result) // chDB
Original file line number Diff line number Diff line change 1
1
const addon = require ( '.' ) ;
2
- var result = addon . Execute ( 'SELECT version()' , 'TabSeparated' ) ;
2
+ const db = new addon . db ( 'CSV' )
3
+ var result ;
4
+
5
+ // Test query
6
+ result = db . query ( "SELECT version()" ) ;
7
+ console . log ( result )
8
+
9
+ // Test session
10
+ db . session ( "CREATE FUNCTION IF NOT EXISTS hello AS () -> 'chDB'" ) ;
11
+ result = db . session ( "SELECT hello()" , "TabSeparated" ) ;
3
12
console . log ( result )
Original file line number Diff line number Diff line change 1
1
//const chdb = require('./build/chdb.node');
2
2
const chdb = require ( 'node-gyp-build' ) ( __dirname )
3
- module . exports = chdb ;
3
+
4
+ function db ( format , path ) {
5
+
6
+ this . format = format || 'JSONCompact' ;
7
+ this . path = path || '.' ;
8
+
9
+ // add properties to this
10
+ this . query = function ( query , format ) {
11
+ return chdb . Execute ( query , format || this . format ) ;
12
+ } . bind ( this ) ;
13
+ this . session = function ( query , format , path ) {
14
+ return chdb . Session ( query , format || this . format , path || this . path ) ;
15
+ } . bind ( this ) ;
16
+
17
+ return this ; ( implicitly )
18
+ }
19
+
20
+ module . exports = { chdb, db } ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " chdb-node" ,
3
- "version" : " 0.11.5 " ,
3
+ "version" : " 0.11.6 " ,
4
4
"description" : " chdb bindings for nodejs" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change 1
- const { Execute } = require ( '..' ) ;
1
+ const { Execute } = require ( '..' ) . chdb ;
2
2
3
3
describe ( "Execution" , ( ) => {
4
4
test ( 'Execute returns correct version' , ( ) => {
You can’t perform that action at this time.
0 commit comments