Skip to content

Commit 3fe22bd

Browse files
committed
nullable sub values
1 parent d4b155e commit 3fe22bd

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/src/query.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Query<T> {
2929
Future<QueryResult<T>?> get future => _onComplete.future;
3030

3131
final String statement;
32-
final Map<String, dynamic> substitutionValues;
32+
final Map<String, dynamic>? substitutionValues;
3333
final PostgreSQLExecutionContext transaction;
3434
final PostgreSQLConnection connection;
3535

@@ -96,7 +96,7 @@ class Query<T> {
9696
}
9797

9898
void sendCachedQuery(Socket socket, CachedQuery cacheQuery,
99-
Map<String, dynamic> substitutionValues) {
99+
Map<String, dynamic>? substitutionValues) {
100100
final statementName = cacheQuery.preparedStatementName;
101101
final parameterList = cacheQuery.orderedParameters!
102102
.map((identifier) => ParameterValue(identifier, substitutionValues))
@@ -196,13 +196,13 @@ class CachedQuery {
196196

197197
class ParameterValue {
198198
factory ParameterValue(PostgreSQLFormatIdentifier identifier,
199-
Map<String, dynamic> substitutionValues) {
199+
Map<String, dynamic>? substitutionValues) {
200200
if (identifier.type == null) {
201-
return ParameterValue.text(substitutionValues[identifier.name]);
201+
return ParameterValue.text(substitutionValues?[identifier.name]);
202202
}
203203

204204
return ParameterValue.binary(
205-
substitutionValues[identifier.name], identifier.type!);
205+
substitutionValues?[identifier.name], identifier.type!);
206206
}
207207

208208
factory ParameterValue.binary(

lib/src/substituter.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ class PostgreSQLFormat {
5252
}
5353
}
5454

55-
static String substitute(String fmtString, Map<String, dynamic> values,
55+
static String substitute(String fmtString, Map<String, dynamic>? values,
5656
{SQLReplaceIdentifierFunction? replace}) {
5757
final converter = PostgresTextEncoder();
58-
replace ??= (spec, index) => converter.convert(values[spec.name]);
58+
replace ??= (spec, index) => converter.convert(values?[spec.name]);
5959

6060
final items = <PostgreSQLFormatToken>[];
6161
PostgreSQLFormatToken? currentPtr;
@@ -114,7 +114,7 @@ class PostgreSQLFormat {
114114
} else {
115115
final identifier = PostgreSQLFormatIdentifier(t.buffer.toString());
116116

117-
if (!values.containsKey(identifier.name)) {
117+
if (values != null && !values.containsKey(identifier.name)) {
118118
// Format string specified identifier with name ${identifier.name},
119119
// but key was not present in values.
120120
return t.buffer;

0 commit comments

Comments
 (0)