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 1616
1717<br >
1818
19- ### Example
20- #### Query _ (query, format)_
19+ ### Examples
20+
21+ #### Query Constructor
2122``` javascript
23+ const addon = require (' .' );
2224const 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 ;
2341var result = chdb .Execute (' SELECT version()' , ' CSV' );
2442console .log (result) // 23.6.1.1
2543```
2644
2745#### Session _ (query, * format, * path)_
2846``` javascript
29- const chdb = require (' chdb-node' );
47+ const chdb = require (' chdb-node' ). chdb ;
3048chdb .Session (" CREATE FUNCTION IF NOT EXISTS hello AS () -> 'chDB'" )
3149var result = = chdb .Session (" SELECT hello();" )
3250console .log (result) // chDB
Original file line number Diff line number Diff line change 11const 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" ) ;
312console . log ( result )
Original file line number Diff line number Diff line change 11//const chdb = require('./build/chdb.node');
22const 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 11{
22 "name" : " chdb-node" ,
3- "version" : " 0.11.5 " ,
3+ "version" : " 0.11.6 " ,
44 "description" : " chdb bindings for nodejs" ,
55 "main" : " index.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change 1- const { Execute } = require ( '..' ) ;
1+ const { Execute } = require ( '..' ) . chdb ;
22
33describe ( "Execution" , ( ) => {
44 test ( 'Execute returns correct version' , ( ) => {
You can’t perform that action at this time.
0 commit comments