diff --git a/extras/drift_postgres/lib/src/pg_database.dart b/extras/drift_postgres/lib/src/pg_database.dart index ac426910..1e870b4f 100644 --- a/extras/drift_postgres/lib/src/pg_database.dart +++ b/extras/drift_postgres/lib/src/pg_database.dart @@ -59,9 +59,8 @@ class _PgDelegate extends DatabaseDelegate { final args = row.arguments; await _ec.execute(stmt, - substitutionValues: args - .asMap() - .map((key, value) => MapEntry((key + 1).toString(), value))); + substitutionValues: args.asMap().map((key, value) => + MapEntry((key + 1).toString(), _convertValue(value)))); } return Future.value(); @@ -74,9 +73,8 @@ class _PgDelegate extends DatabaseDelegate { return _ec.execute(statement); } else { return _ec.execute(statement, - substitutionValues: args - .asMap() - .map((key, value) => MapEntry((key + 1).toString(), value))); + substitutionValues: args.asMap().map((key, value) => + MapEntry((key + 1).toString(), _convertValue(value)))); } } @@ -93,9 +91,8 @@ class _PgDelegate extends DatabaseDelegate { result = await _ec.query(statement); } else { result = await _ec.query(statement, - substitutionValues: args - .asMap() - .map((key, value) => MapEntry((key + 1).toString(), value))); + substitutionValues: args.asMap().map((key, value) => + MapEntry((key + 1).toString(), _convertValue(value)))); } return result.firstOrNull?[0] as int? ?? 0; } @@ -109,9 +106,8 @@ class _PgDelegate extends DatabaseDelegate { Future runSelect(String statement, List args) async { await _ensureOpen(); final result = await _ec.query(statement, - substitutionValues: args - .asMap() - .map((key, value) => MapEntry((key + 1).toString(), value))); + substitutionValues: args.asMap().map((key, value) => + MapEntry((key + 1).toString(), _convertValue(value)))); return Future.value(QueryResult.fromRows( result.map((e) => e.toColumnMap()).toList(growable: false))); @@ -123,6 +119,13 @@ class _PgDelegate extends DatabaseDelegate { await _db.close(); } } + + Object? _convertValue(Object? value) { + if (value is BigInt) { + return value.toInt(); + } + return value; + } } class _PgVersionDelegate extends DynamicVersionDelegate {