Add BigInt support to PgDatabase (#1845)

Add BigInt support to PgDatabase
This commit is contained in:
westito 2022-05-20 10:09:17 +02:00 committed by GitHub
parent e5118c404f
commit a1f5ede720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 12 deletions

View File

@ -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 {