mirror of https://github.com/AMT-Cheif/drift.git
Add BigInt support to PgDatabase (#1845)
Add BigInt support to PgDatabase
This commit is contained in:
parent
e5118c404f
commit
a1f5ede720
|
@ -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<QueryResult> runSelect(String statement, List<Object?> 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 {
|
||||
|
|
Loading…
Reference in New Issue