@@ -75,7 +75,7 @@ export class KyselyDatabaseAdapter implements DatabaseAdapter {
7575 relationLoads : false ,
7676 relationAggregates : true ,
7777 relationFilters : true ,
78- rawWhere : false ,
78+ rawWhere : true ,
7979 }
8080
8181 public constructor (
@@ -578,6 +578,30 @@ export class KyselyDatabaseAdapter implements DatabaseAdapter {
578578 return sql < boolean > `${ column } ${ operator } ${ condition . value } `
579579 }
580580
581+ private buildRawWhereCondition ( condition : QueryRawCondition ) : RawBuilder < boolean > {
582+ const segments = condition . sql . split ( '?' )
583+ const bindings = condition . bindings ?? [ ]
584+
585+ if ( segments . length !== bindings . length + 1 ) {
586+ throw new ArkormException ( 'Raw where bindings do not match the number of placeholders.' )
587+ }
588+
589+ const parts : RawBuilder < unknown > [ ] = [ ]
590+
591+ segments . forEach ( ( segment , index ) => {
592+ if ( segment . length > 0 )
593+ parts . push ( sql . raw ( segment ) )
594+
595+ if ( index < bindings . length )
596+ parts . push ( sql `${ bindings [ index ] } ` )
597+ } )
598+
599+ if ( parts . length === 0 )
600+ return sql < boolean > `1 = 1`
601+
602+ return sql < boolean > `${ sql . join ( parts , sql `` ) } `
603+ }
604+
581605 private buildWhereCondition ( target : QueryTarget < any > , condition ?: QueryCondition ) : RawBuilder < boolean > {
582606 if ( ! condition )
583607 return sql < boolean > `1 = 1`
@@ -607,13 +631,7 @@ export class KyselyDatabaseAdapter implements DatabaseAdapter {
607631 return sql < boolean > `not (${ this . buildWhereCondition ( target , notCondition . condition ) } )`
608632 }
609633
610- throw new UnsupportedAdapterFeatureException ( 'Raw where clauses are not supported by the Kysely adapter.' , {
611- operation : 'adapter.where' ,
612- meta : {
613- feature : 'rawWhere' ,
614- sql : ( condition as QueryRawCondition ) . sql ,
615- } ,
616- } )
634+ return this . buildRawWhereCondition ( condition as QueryRawCondition )
617635 }
618636
619637 private buildWhereClause ( target : QueryTarget < any > , condition ?: QueryCondition ) : RawBuilder < unknown > {
0 commit comments