query function
Executes a SQL query and returns the results.
sql is the SQL query to execute
bind is an optional list of parameters to bind to the query
Implementation
Future<List<Map<String, dynamic>>> query(String sql,
[List<dynamic> bind = const []]) async {
if (_initializationFuture == null) {
throw SqliteException('SQLite is not initialized. Call init() first.');
}
await _initializationFuture;
try {
final jsParams = listToJSArray(bind);
final promise = callSqlite('exec', [sql.toJS, jsParams].toJS);
final result = (await promise.toDart) as JSArray;
return result.toDart
.map((row) => (row.dartify() as Map).cast<String, dynamic>())
.toList();
} catch (e) {
throw SqliteException('Query failed: $e');
}
}