@@ -72,22 +72,22 @@ describe('SqlDriver (QueryAST Format)', () => {
7272 } ) ;
7373
7474 describe ( 'QueryAST Format Support' , ( ) => {
75- it ( 'should support QueryAST with "top" instead of "limit" ' , async ( ) => {
75+ it ( 'should support QueryAST with limit and orderBy ' , async ( ) => {
7676 const results = await driver . find ( 'products' , {
7777 fields : [ 'name' , 'price' ] ,
78- top : 2 ,
79- sort : [ { field : 'price' , order : 'asc' as const } ] ,
78+ limit : 2 ,
79+ orderBy : [ { field : 'price' , order : 'asc' as const } ] ,
8080 } as any ) ;
8181
8282 expect ( results . length ) . toBe ( 2 ) ;
8383 expect ( results [ 0 ] . name ) . toBe ( 'Mouse' ) ;
8484 expect ( results [ 1 ] . name ) . toBe ( 'Chair' ) ;
8585 } ) ;
8686
87- it ( 'should support QueryAST sort format with object notation' , async ( ) => {
87+ it ( 'should support QueryAST orderBy with object notation' , async ( ) => {
8888 const results = await driver . find ( 'products' , {
8989 fields : [ 'name' ] ,
90- sort : [
90+ orderBy : [
9191 { field : 'category' , order : 'asc' as const } ,
9292 { field : 'price' , order : 'desc' as const } ,
9393 ] ,
@@ -98,12 +98,12 @@ describe('SqlDriver (QueryAST Format)', () => {
9898 expect ( results [ 3 ] . name ) . toBe ( 'Desk' ) ;
9999 } ) ;
100100
101- it ( 'should support QueryAST with filters and pagination ' , async ( ) => {
101+ it ( 'should support QueryAST with where, offset, limit, and orderBy ' , async ( ) => {
102102 const results = await driver . find ( 'products' , {
103- filters : [ [ 'category' , '=' , 'Electronics' ] ] ,
104- skip : 1 ,
105- top : 1 ,
106- sort : [ { field : 'price' , order : 'asc' as const } ] ,
103+ where : [ [ 'category' , '=' , 'Electronics' ] ] ,
104+ offset : 1 ,
105+ limit : 1 ,
106+ orderBy : [ { field : 'price' , order : 'asc' as const } ] ,
107107 } as any ) ;
108108
109109 expect ( results . length ) . toBe ( 1 ) ;
@@ -131,20 +131,20 @@ describe('SqlDriver (QueryAST Format)', () => {
131131 expect ( furniture . total_price ) . toBe ( 550 ) ;
132132 } ) ;
133133
134- it ( 'should support count with QueryAST format ' , async ( ) => {
134+ it ( 'should support count with QueryAST where clause ' , async ( ) => {
135135 const count = await driver . count ( 'products' , {
136- filters : [ [ 'price' , '>' , 300 ] ] ,
136+ where : [ [ 'price' , '>' , 300 ] ] ,
137137 } as any ) ;
138138 expect ( count ) . toBe ( 3 ) ;
139139 } ) ;
140140 } ) ;
141141
142- describe ( 'Backward Compatibility ' , ( ) => {
143- it ( 'should still support legacy UnifiedQuery format with "limit" ' , async ( ) => {
142+ describe ( 'Standard QueryAST Pagination ' , ( ) => {
143+ it ( 'should support limit with orderBy using standard keys ' , async ( ) => {
144144 const results = await driver . find ( 'products' , {
145145 fields : [ 'name' ] ,
146146 limit : 2 ,
147- sort : [ [ 'price' , 'asc' ] ] ,
147+ orderBy : [ [ 'price' , 'asc' ] ] ,
148148 } as any ) ;
149149
150150 expect ( results . length ) . toBe ( 2 ) ;
@@ -161,14 +161,12 @@ describe('SqlDriver (QueryAST Format)', () => {
161161 const electronics = results . find ( ( r : any ) => r . category === 'Electronics' ) ;
162162 expect ( electronics . avg_price ) . toBeCloseTo ( 541.67 , 1 ) ;
163163 } ) ;
164- } ) ;
165164
166- describe ( 'Mixed Format Support' , ( ) => {
167- it ( 'should handle query with both top and skip' , async ( ) => {
165+ it ( 'should support offset and limit with orderBy' , async ( ) => {
168166 const results = await driver . find ( 'products' , {
169- top : 3 ,
170- skip : 2 ,
171- sort : [ { field : 'name' , order : 'asc' as const } ] ,
167+ limit : 3 ,
168+ offset : 2 ,
169+ orderBy : [ { field : 'name' , order : 'asc' as const } ] ,
172170 } as any ) ;
173171
174172 expect ( results . length ) . toBe ( 3 ) ;
@@ -177,4 +175,69 @@ describe('SqlDriver (QueryAST Format)', () => {
177175 expect ( results [ 2 ] . name ) . toBe ( 'Mouse' ) ;
178176 } ) ;
179177 } ) ;
178+
179+ describe ( 'Legacy Keys Are Ignored' , ( ) => {
180+ it ( 'should ignore legacy "filters" key — only "where" is recognized' , async ( ) => {
181+ const results = await driver . find ( 'products' , {
182+ filters : [ [ 'category' , '=' , 'Furniture' ] ] ,
183+ } as any ) ;
184+
185+ // "filters" is not recognized, so no WHERE clause is applied — returns all rows
186+ expect ( results . length ) . toBe ( 5 ) ;
187+ } ) ;
188+
189+ it ( 'should use "where" and ignore "filters" when both are present' , async ( ) => {
190+ const results = await driver . find ( 'products' , {
191+ where : [ [ 'category' , '=' , 'Electronics' ] ] ,
192+ filters : [ [ 'category' , '=' , 'Furniture' ] ] ,
193+ } as any ) ;
194+
195+ // Only "where" is applied — returns Electronics, not Furniture
196+ expect ( results . every ( ( r : any ) => r . category === 'Electronics' ) ) . toBe ( true ) ;
197+ expect ( results . length ) . toBe ( 3 ) ;
198+ } ) ;
199+
200+ it ( 'should ignore legacy "sort" key — only "orderBy" is recognized' , async ( ) => {
201+ const results = await driver . find ( 'products' , {
202+ fields : [ 'name' ] ,
203+ limit : 5 ,
204+ orderBy : [ { field : 'price' , order : 'desc' as const } ] ,
205+ sort : [ { field : 'price' , order : 'asc' as const } ] ,
206+ } as any ) ;
207+
208+ // "sort" is ignored; "orderBy" (desc) is applied — most expensive first
209+ expect ( results . length ) . toBe ( 5 ) ;
210+ expect ( results [ 0 ] . name ) . toBe ( 'Laptop' ) ;
211+ expect ( results [ 4 ] . name ) . toBe ( 'Mouse' ) ;
212+ } ) ;
213+
214+ it ( 'should ignore legacy "skip" key — only "offset" is recognized' , async ( ) => {
215+ const results = await driver . find ( 'products' , {
216+ skip : 3 ,
217+ orderBy : [ { field : 'name' , order : 'asc' as const } ] ,
218+ } as any ) ;
219+
220+ // "skip" is not recognized — no offset applied, returns all 5 rows
221+ expect ( results . length ) . toBe ( 5 ) ;
222+ } ) ;
223+
224+ it ( 'should ignore legacy "top" key — only "limit" is recognized' , async ( ) => {
225+ const results = await driver . find ( 'products' , {
226+ top : 2 ,
227+ orderBy : [ { field : 'name' , order : 'asc' as const } ] ,
228+ } as any ) ;
229+
230+ // "top" is not recognized — no limit applied, returns all 5 rows
231+ expect ( results . length ) . toBe ( 5 ) ;
232+ } ) ;
233+
234+ it ( 'should ignore legacy "filters" in count — only "where" is recognized' , async ( ) => {
235+ const count = await driver . count ( 'products' , {
236+ filters : [ [ 'price' , '>' , 300 ] ] ,
237+ } as any ) ;
238+
239+ // "filters" is not recognized — counts all rows
240+ expect ( count ) . toBe ( 5 ) ;
241+ } ) ;
242+ } ) ;
180243} ) ;
0 commit comments