query method

Future<List<Map<String, Object?>>> query(
  1. String sql, [
  2. List<Object?>? args
])

Performs a SQL query with optional args and returns the result as a list of column maps. Use "?" placeholders for parameters to avoid injection vulnerabilities:

final result = await crdt.query(
  'SELECT id, name FROM users WHERE id = ?1', [1]);
print(result.isEmpty ? 'User not found' : result.first['name']);

Implementation

Future<List<Map<String, Object?>>> query(String sql, [List<Object?>? args]) =>
    _db.query(sql, args?.map(_convert).toList());