Skip to content

Commit 7e34871

Browse files
committed
add support for special bindings in inserts. useful for binary data.
1 parent 5bfd946 commit 7e34871

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/src/database_access.dart

+18-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,19 @@ class DatabaseTransactionBase<TABLES extends TablesBase> {
3232
_assertColumnNames(values);
3333
final entries = values.entries.toList();
3434
final columnList = entries.map((e) => e.key).join(',');
35-
final bindList = entries.map((e) => '@${e.key}').join(',');
35+
final bindList = entries.map((e) => _bindForEntry(e)).join(',');
3636
return await execute('INSERT INTO $table ($columnList) VALUES ($bindList)',
37-
values: values, expectedResultCount: 1);
37+
values: values.map((key, value) =>
38+
MapEntry(key, value is CustomBind ? value.value : value)),
39+
expectedResultCount: 1);
40+
}
41+
42+
String _bindForEntry(MapEntry<String, Object> entry) {
43+
final value = entry.value;
44+
if (value is CustomBind) {
45+
return value.bind;
46+
}
47+
return '@${entry.key}';
3848
}
3949

4050
Future<int> executeUpdate(
@@ -127,6 +137,12 @@ class DatabaseTransactionBase<TABLES extends TablesBase> {
127137
}
128138
}
129139

140+
class CustomBind {
141+
CustomBind(this.bind, this.value);
142+
final String bind;
143+
final Object value;
144+
}
145+
130146
abstract class DatabaseAccessBase<TX extends DatabaseTransactionBase<TABLES>,
131147
TABLES extends TablesBase> {
132148
DatabaseAccessBase({

0 commit comments

Comments
 (0)