1212use Tempest \Database \Connection \Connection ;
1313use Tempest \Database \Exceptions \QueryWasInvalid ;
1414use Tempest \Database \Transactions \TransactionManager ;
15+ use Tempest \Mapper \Context ;
1516use Tempest \Mapper \SerializerFactory ;
1617use Throwable ;
1718use UnitEnum ;
@@ -29,6 +30,14 @@ final class GenericDatabase implements Database
2930 get => $ this ->connection ->config ->tag ;
3031 }
3132
33+ private string $ context {
34+ get => match ($ this ->dialect ) {
35+ DatabaseDialect::POSTGRESQL => Context::DATABASE_POSTGRESQL ,
36+ DatabaseDialect::MYSQL => Context::DATABASE_MYSQL ,
37+ DatabaseDialect::SQLITE => Context::DATABASE_SQLITE ,
38+ };
39+ }
40+
3241 public function __construct (
3342 private(set) readonly Connection $ connection ,
3443 private(set) readonly TransactionManager $ transactionManager ,
@@ -128,17 +137,9 @@ private function resolveBindings(Query $query): array
128137 $ bindings = [];
129138
130139 foreach ($ query ->bindings as $ key => $ value ) {
131- // Database handle booleans differently. We might need a database-aware serializer at some point.
132- if (is_bool ($ value )) {
133- $ value = match ($ this ->dialect ) {
134- DatabaseDialect::POSTGRESQL => $ value ? 'true ' : 'false ' ,
135- default => $ value ? '1 ' : '0 ' ,
136- };
137- }
138-
139140 if ($ value instanceof Query) {
140141 $ value = $ value ->execute ();
141- } elseif ($ serializer = $ this ->serializerFactory ->forValue ($ value )) {
142+ } elseif ($ serializer = $ this ->serializerFactory ->forValue ($ value, $ this -> context )) {
142143 $ value = $ serializer ->serialize ($ value );
143144 }
144145
0 commit comments