@@ -26,13 +26,15 @@ export class InMemoryDriver implements DriverInterface {
2626 queryFilters : false , // TODO: Not implemented - basic find() doesn't handle filters
2727 queryAggregations : false , // TODO: Not implemented - count() only returns total
2828 querySorting : false , // TODO: Not implemented - find() doesn't handle sorting
29- queryPagination : true , // Basic pagination via 'top ' is implemented
29+ queryPagination : true , // Basic pagination via 'limit ' is implemented
3030 queryWindowFunctions : false , // TODO: Not implemented
3131 querySubqueries : false , // TODO: Not implemented
3232 joins : false , // TODO: Not implemented
3333
3434 // Advanced Features
3535 fullTextSearch : false , // TODO: Not implemented
36+ vectorSearch : false , // TODO: Not implemented
37+ geoSpatial : false , // TODO: Not implemented
3638 jsonFields : true , // Native JS object support
3739 arrayFields : true , // Native JS array support
3840 } ;
@@ -79,15 +81,22 @@ export class InMemoryDriver implements DriverInterface {
7981 let results = [ ...table ] ;
8082
8183 // Simple limiting for demonstration
82- if ( query . top ) {
83- results = results . slice ( 0 , query . top ) ;
84+ if ( query . limit ) {
85+ results = results . slice ( 0 , query . limit ) ;
8486 }
8587
8688 return results ;
8789 }
8890
91+ async * findStream ( object : string , query : QueryInput , options ?: DriverOptions ) {
92+ const results = await this . find ( object , query , options ) ;
93+ for ( const record of results ) {
94+ yield record ;
95+ }
96+ }
97+
8998 async findOne ( object : string , query : QueryInput , options ?: DriverOptions ) {
90- const results = await this . find ( object , { ...query , top : 1 } , options ) ;
99+ const results = await this . find ( object , { ...query , limit : 1 } , options ) ;
91100 return results [ 0 ] || null ;
92101 }
93102
@@ -124,6 +133,23 @@ export class InMemoryDriver implements DriverInterface {
124133 return updatedRecord ;
125134 }
126135
136+ async upsert ( object : string , data : Record < string , any > , conflictKeys ?: string [ ] , options ?: DriverOptions ) {
137+ const table = this . getTable ( object ) ;
138+ let existingRecord : any = null ;
139+
140+ if ( data . id ) {
141+ existingRecord = table . find ( r => r . id === data . id ) ;
142+ } else if ( conflictKeys && conflictKeys . length > 0 ) {
143+ existingRecord = table . find ( r => conflictKeys . every ( key => r [ key ] === data [ key ] ) ) ;
144+ }
145+
146+ if ( existingRecord ) {
147+ return this . update ( object , existingRecord . id , data , options ) ;
148+ } else {
149+ return this . create ( object , data , options ) ;
150+ }
151+ }
152+
127153 async delete ( object : string , id : string | number , options ?: DriverOptions ) {
128154 const table = this . getTable ( object ) ;
129155 const index = table . findIndex ( r => r . id == id ) ;
0 commit comments