File tree 3 files changed +51
-1
lines changed
3 files changed +51
-1
lines changed Original file line number Diff line number Diff line change
1
+ import sqlite3InitModule from '../node.mjs' ;
2
+
3
+ const log = ( ...args ) => console . log ( ...args ) ;
4
+ const error = ( ...args ) => console . error ( ...args ) ;
5
+
6
+ const start = function ( sqlite3 ) {
7
+ log ( 'Running SQLite3 version' , sqlite3 . version . libVersion ) ;
8
+
9
+ const db = new sqlite3 . oo1 . DB ( './local' , 'cw' ) ;
10
+
11
+ try {
12
+ log ( 'Creating a table...' ) ;
13
+ db . exec ( 'CREATE TABLE IF NOT EXISTS t(a,b)' ) ;
14
+ log ( 'Insert some data using exec()...' ) ;
15
+ for ( let i = 20 ; i <= 25 ; ++ i ) {
16
+ db . exec ( {
17
+ sql : 'INSERT INTO t(a,b) VALUES (?,?)' ,
18
+ bind : [ i , i * 2 ] ,
19
+ } ) ;
20
+ }
21
+ log ( 'Query data with exec()...' ) ;
22
+ db . exec ( {
23
+ sql : 'SELECT a FROM t ORDER BY a LIMIT 3' ,
24
+ callback : ( row ) => {
25
+ log ( row ) ;
26
+ } ,
27
+ } ) ;
28
+ } finally {
29
+ db . close ( ) ;
30
+ }
31
+ } ;
32
+
33
+ log ( 'Loading and initializing SQLite3 module...' ) ;
34
+ sqlite3InitModule ( {
35
+ print : log ,
36
+ printErr : error ,
37
+ } ) . then ( ( sqlite3 ) => {
38
+ log ( 'Done initializing. Running demo...' ) ;
39
+ try {
40
+ start ( sqlite3 ) ;
41
+ } catch ( err ) {
42
+ error ( err . name , err . message ) ;
43
+ }
44
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { default as sqlite3InitModule } from './sqlite-wasm/jswasm/sqlite3-node.mjs' ;
2
+
3
+ export default sqlite3InitModule ;
Original file line number Diff line number Diff line change 14
14
" origin-private-file-system"
15
15
],
16
16
"main" : " index.mjs" ,
17
+ "node" : " node.mjs" ,
17
18
"type" : " module" ,
18
19
"files" : [
19
20
" index.d.ts" ,
20
21
" index.mjs" ,
22
+ " node.mjs" ,
21
23
" sqlite-wasm/"
22
24
],
23
25
"types" : " index.d.ts" ,
24
26
"exports" : {
25
27
"." : {
26
28
"types" : " ./index.d.ts" ,
27
- "node" : " ./index .mjs" ,
29
+ "node" : " ./node .mjs" ,
28
30
"import" : " ./index.mjs" ,
29
31
"main" : " ./index.mjs" ,
30
32
"browser" : " ./index.mjs"
41
43
"clean" : " shx rm -rf sqlite-wasm" ,
42
44
"build" : " npm run clean && node bin/index.js" ,
43
45
"start" : " npx http-server --coop" ,
46
+ "start:node" : " cd demo && node node.mjs" ,
44
47
"fix" : " npx prettier . --write" ,
45
48
"prepublishOnly" : " npm run build && npm run fix && npm run publint && npm run check-types" ,
46
49
"deploy" : " npm run prepublishOnly && git add . && git commit -am 'New release' && git push && npm publish --access public"
You can’t perform that action at this time.
0 commit comments