77 * Supports PostgreSQL, MySQL, SQLite, and other SQL databases.
88 */
99
10- import type { QueryInput , DriverOptions } from '@objectstack/spec/data' ;
10+ import type { QueryAST , DriverOptions } from '@objectstack/spec/data' ;
1111import type { IDataDriver } from '@objectstack/spec/contracts' ;
1212import knex , { Knex } from 'knex' ;
1313import { nanoid } from 'nanoid' ;
@@ -167,7 +167,7 @@ export class SqlDriver implements IDataDriver {
167167 // CRUD — DriverInterface core
168168 // ===================================
169169
170- async find ( object : string , query : QueryInput , options ?: DriverOptions ) : Promise < any [ ] > {
170+ async find ( object : string , query : QueryAST , options ?: DriverOptions ) : Promise < any [ ] > {
171171 const builder = this . getBuilder ( object , options ) ;
172172
173173 // SELECT
@@ -228,7 +228,7 @@ export class SqlDriver implements IDataDriver {
228228 return results ;
229229 }
230230
231- async findOne ( object : string , query : QueryInput , options ?: DriverOptions ) : Promise < any > {
231+ async findOne ( object : string , query : QueryAST , options ?: DriverOptions ) : Promise < any > {
232232 // When called with a string/number id fall back gracefully
233233 if ( typeof query === 'string' || typeof query === 'number' ) {
234234 const res = await this . getBuilder ( object , options ) . where ( 'id' , query ) . first ( ) ;
@@ -248,7 +248,7 @@ export class SqlDriver implements IDataDriver {
248248 * NOTE: Current implementation fetches all results then yields them.
249249 * TODO: Use Knex .stream() for true cursor-based streaming on large datasets.
250250 */
251- async * findStream ( object : string , query : QueryInput , options ?: DriverOptions ) : AsyncGenerator < Record < string , any > > {
251+ async * findStream ( object : string , query : QueryAST , options ?: DriverOptions ) : AsyncGenerator < Record < string , any > > {
252252 const results = await this . find ( object , query , options ) ;
253253 for ( const row of results ) {
254254 yield row ;
@@ -345,23 +345,23 @@ export class SqlDriver implements IDataDriver {
345345 await builder . whereIn ( 'id' , ids ) . delete ( ) ;
346346 }
347347
348- async updateMany ( object : string , query : QueryInput , data : any , options ?: DriverOptions ) : Promise < number > {
348+ async updateMany ( object : string , query : QueryAST , data : any , options ?: DriverOptions ) : Promise < number > {
349349 const builder = this . getBuilder ( object , options ) ;
350350 const filters = query . where || ( query as any ) . filters || query ;
351351 if ( filters ) this . applyFilters ( builder , filters ) ;
352352 const count = await builder . update ( data ) ;
353353 return count || 0 ;
354354 }
355355
356- async deleteMany ( object : string , query : QueryInput , options ?: DriverOptions ) : Promise < number > {
356+ async deleteMany ( object : string , query : QueryAST , options ?: DriverOptions ) : Promise < number > {
357357 const builder = this . getBuilder ( object , options ) ;
358358 const filters = query . where || ( query as any ) . filters || query ;
359359 if ( filters ) this . applyFilters ( builder , filters ) ;
360360 const count = await builder . delete ( ) ;
361361 return count || 0 ;
362362 }
363363
364- async count ( object : string , query : QueryInput , options ?: DriverOptions ) : Promise < number > {
364+ async count ( object : string , query ?: QueryAST , options ?: DriverOptions ) : Promise < number > {
365365 const builder = this . getBuilder ( object , options ) ;
366366
367367 let actualFilters = query as any ;
0 commit comments