@@ -74,23 +74,23 @@ The test files provide up to date example of the use of the api.
7474``` html
7575<script src =' js/sql.js' ></script >
7676<script >
77- // Create the database
78- var db = new SQL.Database ();
79- // Run a query without reading the results
80- db .run (" CREATE TABLE test (col1, col2);" );
81- // Insert two rows: (1,111) and (2,222)
82- db .run (" INSERT INTO test VALUES (?,?), (?,?)" , [1 ,111 ,2 ,222 ]);
83-
84- // Prepare a statement
85- var stmt = db .prepare (" SELECT * FROM test WHERE col1 BETWEEN $start AND $end" );
86- stmt .getAsObject ({$start: 1 , $end: 1 }); // {col1:1, col2:111}
87-
88- // Bind new values
89- stmt .bind ({$start: 1 , $end: 2 });
90- while (stmt .step ()) { //
91- var row = stmt .getAsObject ();
92- // [...] do something with the row of result
93- }
77+ // Create the database
78+ var db = new SQL.Database ();
79+ // Run a query without reading the results
80+ db .run (" CREATE TABLE test (col1, col2);" );
81+ // Insert two rows: (1,111) and (2,222)
82+ db .run (" INSERT INTO test VALUES (?,?), (?,?)" , [1 ,111 ,2 ,222 ]);
83+
84+ // Prepare a statement
85+ var stmt = db .prepare (" SELECT * FROM test WHERE col1 BETWEEN $start AND $end" );
86+ stmt .getAsObject ({$start: 1 , $end: 1 }); // {col1:1, col2:111}
87+
88+ // Bind new values
89+ stmt .bind ({$start: 1 , $end: 2 });
90+ while (stmt .step ()) { //
91+ var row = stmt .getAsObject ();
92+ // [...] do something with the row of result
93+ }
9494 </script >
9595```
9696
@@ -99,13 +99,13 @@ The test files provide up to date example of the use of the api.
9999The following code uses an HTML input as the source for loading a database:
100100``` javascript
101101dbFileElm .onchange = function () {
102- var f = dbFileElm .files [0 ];
103- var r = new FileReader ();
104- r .onload = function () {
105- var Uints = new Uint8Array (r .result );
106- db = new SQL.Database (Uints);
107- }
108- r .readAsArrayBuffer (f);
102+ var f = dbFileElm .files [0 ];
103+ var r = new FileReader ();
104+ r .onload = function () {
105+ var Uints = new Uint8Array (r .result );
106+ db = new SQL.Database (Uints);
107+ }
108+ r .readAsArrayBuffer (f);
109109}
110110```
111111See : http://kripken.github.io/sql.js/GUI/gui.js
@@ -164,25 +164,26 @@ You will need to download `worker.sql.js`
164164Example:
165165``` html
166166<script >
167- var worker = new Worker (" js/worker.sql.js" ); // You can find worker.sql.js in this repo
168- worker .onmessage = function () {
169- console .log (" Database opened" );
170- worker .onmessage = function (event ){
171- console .log (event .data ); // The result of the query
172- };
173- worker .postMessage ({
174- id: 2 ,
175- action: ' exec' ,
176- sql: ' SELECT * FROM test'
177- });
178- };
179-
180- worker .onerror = function (e ) {console .log (" Worker error: " , e)};
181- worker .postMessage ({
182- id: 1 ,
183- action: ' open' ,
184- buffer: buf, /* Optional. An ArrayBuffer representing an SQLite Database file*/
185- });
167+ var worker = new Worker (" js/worker.sql.js" ); // You can find worker.sql.js in this repo
168+ worker .onmessage = function () {
169+ console .log (" Database opened" );
170+ worker .onmessage = function (event ){
171+ console .log (event .data ); // The result of the query
172+ };
173+
174+ worker .postMessage ({
175+ id: 2 ,
176+ action: ' exec' ,
177+ sql: ' SELECT * FROM test'
178+ });
179+ };
180+
181+ worker .onerror = function (e ) {console .log (" Worker error: " , e)};
182+ worker .postMessage ({
183+ id: 1 ,
184+ action: ' open' ,
185+ buffer: buf, /* Optional. An ArrayBuffer representing an SQLite Database file*/
186+ });
186187 </script >
187188```
188189
0 commit comments