@@ -36,16 +36,19 @@ class DatabaseTransactionBase<TABLES extends TablesBase> {
36
36
final entries = values.entries.toList ();
37
37
final columnList = entries.map ((e) => e.key).join (',' );
38
38
final bindList = entries.map ((e) => _bindForEntry (e)).join (',' );
39
- return await execute ('INSERT INTO $table ($columnList ) VALUES ($bindList )' ,
40
- values: values.map ((key, value) =>
41
- MapEntry (key, value is CustomBind ? value.value : value)),
42
- expectedResultCount: 1 );
39
+ return await execute (
40
+ 'INSERT INTO $table ($columnList ) VALUES ($bindList )' ,
41
+ values: values.map ((key, value) =>
42
+ MapEntry (key, value is CustomBind ? value.value : value)),
43
+ expectedResultCount: 1 ,
44
+ useExtendedQuery: true ,
45
+ );
43
46
}
44
47
45
48
String _bindForEntry (MapEntry <String , Object ?> entry) {
46
49
final value = entry.value;
47
50
if (value is CustomBind ) {
48
- return value.bind ;
51
+ return value.formatString (entry.key) ;
49
52
}
50
53
return '@${entry .key }' ;
51
54
}
@@ -116,12 +119,21 @@ class DatabaseTransactionBase<TABLES extends TablesBase> {
116
119
Map <String , Object ?>? values,
117
120
int ? timeoutInSeconds,
118
121
int ? expectedResultCount,
122
+ bool useExtendedQuery = false ,
119
123
}) async {
120
124
try {
121
125
assert (_assertCorrectValues (values));
122
126
_logger.finest ('Executing query: $fmtString with values: $values ' );
123
- final result = await _conn.execute (fmtString,
124
- substitutionValues: values, timeoutInSeconds: timeoutInSeconds);
127
+
128
+ final int result;
129
+ if (useExtendedQuery) {
130
+ final sqlResult = await _conn.query (fmtString,
131
+ substitutionValues: values, timeoutInSeconds: timeoutInSeconds);
132
+ result = sqlResult.affectedRowCount;
133
+ } else {
134
+ result = await _conn.execute (fmtString,
135
+ substitutionValues: values, timeoutInSeconds: timeoutInSeconds);
136
+ }
125
137
if (expectedResultCount != null && result != expectedResultCount) {
126
138
throw StateError (
127
139
'Expected result: $expectedResultCount but got $result . '
@@ -155,9 +167,29 @@ class DatabaseTransactionBase<TABLES extends TablesBase> {
155
167
}
156
168
157
169
class CustomBind {
158
- CustomBind (this .bind , this .value);
159
- final String bind ;
170
+ CustomBind (this ._bind , this .value, { this .type} );
171
+ final String _bind ;
160
172
final Object value;
173
+ final PostgreSQLDataType ? type;
174
+
175
+ String formatString (String bindName) => _bind;
176
+ }
177
+
178
+ class CustomTypeBind extends CustomBind {
179
+ factory CustomTypeBind (PostgreSQLDataType type, Object value) {
180
+ // _bindCount.to
181
+ return CustomTypeBind ._(
182
+ '' ,
183
+ value,
184
+ type,
185
+ );
186
+ }
187
+ CustomTypeBind ._(String bind, Object value, PostgreSQLDataType type)
188
+ : super (bind, value, type: type);
189
+
190
+ @override
191
+ String formatString (String bindName) =>
192
+ '${PostgreSQLFormat .id (bindName )}::jsonb' ;
161
193
}
162
194
163
195
abstract class DatabaseAccessBase <TX extends DatabaseTransactionBase <TABLES >,
0 commit comments