@@ -250,6 +250,7 @@ export class SqliteOrm {
250250 for ( const col of this . models [ table . name ] . columns ) {
251251 ( parsed as Record < string , unknown > ) [ col . name ] = this . deseralize ( datum [ col . mappedTo ?? col . name ] , col . type ) ;
252252 }
253+ parsed . _new = false ;
253254 parsedAll . push ( parsed ) ;
254255 }
255256
@@ -266,31 +267,31 @@ export class SqliteOrm {
266267 return this . db . prepare ( builtQuery . query ) . values ( ...builtQuery . params ) ;
267268 }
268269
269- public save < T extends SqlTable > ( table : T ) : T {
270- const model = this . models [ table . constructor . name ] ;
270+ public save < T extends SqlTable > ( obj : T ) : T {
271+ const model = this . models [ obj . constructor . name ] ;
271272
272273 const builtData : Record < string , unknown > = { } ;
273274 model . columns . forEach ( ( col ) => {
274- builtData [ col . mappedTo ?? col . name ] = this . serialize ( ( table as Record < string , unknown > ) [ col . name ] , col . type ) ;
275+ builtData [ col . mappedTo ?? col . name ] = this . serialize ( ( obj as Record < string , unknown > ) [ col . name ] , col . type ) ;
275276 } ) ;
276277
277- if ( table . _new ) {
278+ if ( obj . _new ) {
278279 const builtQuery = buildInsertQuery ( model , builtData ) ;
279280 this . db . exec ( builtQuery . query , ...builtQuery . params ) ;
280281
281282 const incrementPrimaryKey = model . columns . find ( ( c ) => c . isPrimaryKey && c . autoIncrement ) ;
282283 if ( incrementPrimaryKey ) {
283- ( table as Record < string , unknown > ) [ incrementPrimaryKey . name ] = this . db . lastInsertRowId ;
284+ ( obj as Record < string , unknown > ) [ incrementPrimaryKey . name ] = this . db . lastInsertRowId ;
284285 }
285286
286- table . _new = false ;
287+ obj . _new = false ;
287288 } else {
288289 const builtQuery = buildUpdateQuery ( model , builtData ) ;
289290 this . db . exec ( builtQuery . query , ...builtQuery . params ) ;
290291 }
291292 this . hasChangesSinceBackup = true ;
292293
293- return table ;
294+ return obj ;
294295 }
295296
296297 public delete < T extends SqlTable > ( table : new ( ) => T , query : DeleteQuery ) {
0 commit comments