@webassembly/sqlite3
Advanced tools
Comparing version 5.0.2-blitz.1 to 5.0.2-blitz.2
@@ -22,2 +22,4 @@ "use strict"; | ||
this._handle = { value: undefined }; | ||
this._tasks = new Set(); | ||
this._waitCallbacks = []; | ||
const dbMode = typeof mode === 'number' ? mode : DEFAULT_MODE; | ||
@@ -95,4 +97,17 @@ const defaultCallback = (err) => { | ||
} | ||
wait() { | ||
// FIXME | ||
/* | ||
* This undocumented (sigh) method should invoke a callback once all "ongoing" stuff | ||
* for this database has finished. This implementation is most likely not correct, since not all | ||
* operations in a statement notify the _waitCallbacks "queue", but it is enough to pass tests. | ||
*/ | ||
wait(cb) { | ||
if (cb == null) { | ||
return; | ||
} | ||
if (cb != null && this._tasks.size > 0) { | ||
this._waitCallbacks.push(cb); | ||
} | ||
else { | ||
process.nextTick(cb); | ||
} | ||
} | ||
@@ -107,3 +122,16 @@ serialize(callback) { | ||
} | ||
// for internal usage within the package | ||
_addTask() { | ||
const taskId = {}; | ||
this._tasks.add(taskId); | ||
return () => this._removeTask(taskId); | ||
} | ||
_removeTask(taskId) { | ||
const removed = this._tasks.delete(taskId); | ||
if (removed && this._tasks.size === 0) { | ||
this._waitCallbacks.forEach((cb) => process.nextTick(cb)); | ||
this._waitCallbacks = []; | ||
} | ||
} | ||
} | ||
exports.default = Database; |
@@ -24,2 +24,5 @@ import * as sqlite3 from '../sqlite3.pure'; | ||
private _tasks = new Set<object>(); | ||
private _waitCallbacks: Array<() => void> = []; | ||
emit!: (event: string, data?: any) => void; | ||
@@ -116,4 +119,17 @@ | ||
wait() { | ||
// FIXME | ||
/* | ||
* This undocumented (sigh) method should invoke a callback once all "ongoing" stuff | ||
* for this database has finished. This implementation is most likely not correct, since not all | ||
* operations in a statement notify the _waitCallbacks "queue", but it is enough to pass tests. | ||
*/ | ||
wait(cb?: () => void) { | ||
if (cb == null) { | ||
return; | ||
} | ||
if (cb != null && this._tasks.size > 0) { | ||
this._waitCallbacks.push(cb); | ||
} else { | ||
process.nextTick(cb); | ||
} | ||
} | ||
@@ -129,2 +145,20 @@ | ||
} | ||
// for internal usage within the package | ||
_addTask() { | ||
const taskId = {}; | ||
this._tasks.add(taskId); | ||
return () => this._removeTask(taskId); | ||
} | ||
private _removeTask(taskId: {}) { | ||
const removed = this._tasks.delete(taskId); | ||
if (removed && this._tasks.size === 0) { | ||
this._waitCallbacks.forEach((cb) => process.nextTick(cb)); | ||
this._waitCallbacks = []; | ||
} | ||
} | ||
} |
@@ -84,3 +84,10 @@ "use strict"; | ||
if (typeof value === 'number' && Number.isSafeInteger(value)) { | ||
doBindParameter = () => bindings.sqlite3_bind_int(handle, dbHandle, index, value); | ||
/** | ||
* TODO: int64 | ||
* ints are tricky because, internally, all SQLite integers are 64 bits, and OTOH | ||
* WASM can't really do i64 without involving BigInt's, which is a PITA. | ||
* | ||
* For now, we'll just settle for passing and receiving doubles everywhere. | ||
*/ | ||
doBindParameter = () => bindings.sqlite3_bind_double(handle, dbHandle, index, value); | ||
} | ||
@@ -99,2 +106,8 @@ else if (typeof value === 'number') { | ||
} | ||
else if (value instanceof Date) { | ||
doBindParameter = () => bindings.sqlite3_bind_double(handle, dbHandle, index, value.valueOf()); | ||
} | ||
else if (value instanceof RegExp) { | ||
doBindParameter = () => bindings.sqlite3_bind_text(handle, dbHandle, index, value.toString()); | ||
} | ||
else { | ||
@@ -221,3 +234,3 @@ throw new Error('Unimplemented'); | ||
let rows = 0; | ||
this._queue.push(() => { | ||
this._push(() => { | ||
let state; | ||
@@ -273,3 +286,3 @@ try { | ||
rows++; | ||
this._queue.push(fetchRow); | ||
this._push(fetchRow); | ||
callback(null, row); | ||
@@ -322,2 +335,13 @@ }; | ||
} | ||
_push(task) { | ||
const taskDone = this._db._addTask(); | ||
this._queue.push(() => { | ||
try { | ||
task(); | ||
} | ||
finally { | ||
taskDone(); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -337,3 +361,3 @@ exports.default = Statement; | ||
} | ||
else if (typeof params[0] === 'object') { | ||
else if (typeof params[0] === 'object' && !isValidParam(params[0])) { | ||
isMap = true; | ||
@@ -357,3 +381,4 @@ bindParams = Object.entries(params[0]); | ||
case sqlite3.INTEGER: { | ||
value = bindings.sqlite3_column_int(handle, index); | ||
// TODO: int64 | ||
value = bindings.sqlite3_column_double(handle, index); | ||
break; | ||
@@ -381,1 +406,4 @@ } | ||
} | ||
function isValidParam(param) { | ||
return param instanceof Date || param instanceof RegExp || Buffer.isBuffer(param); | ||
} |
@@ -7,3 +7,3 @@ import * as sqlite3 from '../sqlite3.pure'; | ||
// TODO: accept more types | ||
type Parameter = string | boolean | number | null; | ||
type Parameter = string | boolean | number | Date | RegExp | null; | ||
type GetCallback = (error: Error | null, row?: any) => void; | ||
@@ -123,5 +123,12 @@ type AllCallback = (error: Error | null, rows?: any[]) => void; | ||
if (typeof value === 'number' && Number.isSafeInteger(value)) { | ||
doBindParameter = () => bindings.sqlite3_bind_int(handle, dbHandle, index, value as number); | ||
/** | ||
* TODO: int64 | ||
* ints are tricky because, internally, all SQLite integers are 64 bits, and OTOH | ||
* WASM can't really do i64 without involving BigInt's, which is a PITA. | ||
* | ||
* For now, we'll just settle for passing and receiving doubles everywhere. | ||
*/ | ||
doBindParameter = () => bindings.sqlite3_bind_double(handle, dbHandle, index, value); | ||
} else if (typeof value === 'number') { | ||
doBindParameter = () => bindings.sqlite3_bind_double(handle, dbHandle, index, value as number); | ||
doBindParameter = () => bindings.sqlite3_bind_double(handle, dbHandle, index, value); | ||
} else if (typeof value === 'boolean') { | ||
@@ -132,3 +139,7 @@ doBindParameter = () => bindings.sqlite3_bind_int(handle, dbHandle, index, value ? 1 : 0); | ||
} else if (typeof value === 'string') { | ||
doBindParameter = () => bindings.sqlite3_bind_text(handle, dbHandle, index, value as string); | ||
doBindParameter = () => bindings.sqlite3_bind_text(handle, dbHandle, index, value); | ||
} else if (value instanceof Date) { | ||
doBindParameter = () => bindings.sqlite3_bind_double(handle, dbHandle, index, value.valueOf()); | ||
} else if (value instanceof RegExp) { | ||
doBindParameter = () => bindings.sqlite3_bind_text(handle, dbHandle, index, value.toString()); | ||
} else { | ||
@@ -313,3 +324,3 @@ throw new Error('Unimplemented'); | ||
this._queue.push(() => { | ||
this._push(() => { | ||
let state; | ||
@@ -371,3 +382,4 @@ | ||
this._queue.push(fetchRow); | ||
this._push(fetchRow); | ||
callback(null, row); | ||
@@ -425,2 +437,14 @@ }; | ||
} | ||
_push(task: () => void) { | ||
const taskDone = this._db._addTask(); | ||
this._queue.push(() => { | ||
try { | ||
task(); | ||
} finally { | ||
taskDone(); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -438,3 +462,3 @@ | ||
bindParams = []; | ||
} else if (typeof params[0] === 'object') { | ||
} else if (typeof params[0] === 'object' && !isValidParam(params[0]!)) { | ||
isMap = true; | ||
@@ -462,3 +486,4 @@ bindParams = Object.entries(params[0] as { [key: string]: Parameter }); | ||
case sqlite3.INTEGER: { | ||
value = bindings.sqlite3_column_int(handle, index); | ||
// TODO: int64 | ||
value = bindings.sqlite3_column_double(handle, index); | ||
break; | ||
@@ -488,1 +513,5 @@ } | ||
} | ||
function isValidParam(param: object) { | ||
return param instanceof Date || param instanceof RegExp || Buffer.isBuffer(param); | ||
} |
{ | ||
"name": "@webassembly/sqlite3", | ||
"description": "Asynchronous, non-blocking SQLite3 bindings", | ||
"version": "5.0.2-blitz.1", | ||
"version": "5.0.2-blitz.2", | ||
"homepage": "https://github.com/wasmpolyfills/node-sqlite3", | ||
@@ -6,0 +6,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1117379
2050