aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-oo1.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-06 06:09:03 +0000
committerstephan <stephan@noemail.net>2022-12-06 06:09:03 +0000
commit6b271abc9853e77a19bb208893c6e2a3924e9f50 (patch)
treefd115002a9db42e555e256c1a47812209c0e9232 /ext/wasm/api/sqlite3-api-oo1.js
parent2582d418d3acf2932c438ad26726d8f1976463ae (diff)
downloadsqlite-6b271abc9853e77a19bb208893c6e2a3924e9f50.tar.gz
sqlite-6b271abc9853e77a19bb208893c6e2a3924e9f50.zip
Add a demonstration sqlite3_vtab/module implemented in JS, based on ext/misc/templatevtab.c. Add oo1.selectArrays() and selectObjects().
FossilOrigin-Name: 60482c97e02bc4cafefef281be0cf0bc8c5c53232162829c137f3f7a80cdc534
Diffstat (limited to 'ext/wasm/api/sqlite3-api-oo1.js')
-rw-r--r--ext/wasm/api/sqlite3-api-oo1.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js
index b377efc24..6253c659f 100644
--- a/ext/wasm/api/sqlite3-api-oo1.js
+++ b/ext/wasm/api/sqlite3-api-oo1.js
@@ -474,6 +474,15 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
};
/**
+ Internal impl of the DB.selectArrays() and
+ selectObjects() methods.
+ */
+ const __selectAll =
+ (db, sql, bind, rowMode)=>db.exec({
+ sql, bind, rowMode, returnValue: 'resultRows'
+ });
+
+ /**
Expects to be given a DB instance or an `sqlite3*` pointer (may
be null) and an sqlite3 API result code. If the result code is
not falsy, this function throws an SQLite3Error with an error
@@ -1099,6 +1108,26 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
},
/**
+ Runs the given SQL and returns an array of all results, with
+ each row represented as an array, as per the 'array' `rowMode`
+ option to `exec()`. An empty result set resolves
+ to an empty array. The second argument, if any, is treated as
+ the 'bind' option to a call to exec().
+ */
+ selectArrays: function(sql,bind){
+ return __selectAll(this, sql, bind, 'array');
+ },
+
+ /**
+ Works identically to selectArrays() except that each value
+ in the returned array is an object, as per the 'object' `rowMode`
+ option to `exec()`.
+ */
+ selectObjects: function(sql,bind){
+ return __selectAll(this, sql, bind, 'object');
+ },
+
+ /**
Returns the number of currently-opened Stmt handles for this db
handle, or 0 if this DB instance is closed.
*/