@@ -297,10 +297,26 @@ const productIds = await database
297297 .buildTable (' products' )
298298 .insert ([{ name: ' iPhone 10' }, { name: ' iPhone 11' }, { name: ' iPhone 12' }])
299299
300+ // WARN - ONLY FOR SQL
301+ {
302+ // When Database insert the data he will always return an array of ID.
303+ // But you can change this behavior setting the returnKey value
304+ const returnKey = ' name'
305+ const productNames = await database
306+ .buildTable (' products' )
307+ .insert ([{ name: ' iPhone 13' }], returnKey )
308+
309+ // The returnKey can be defined only in SQL Drivers because Mongo always returns the _id by default
310+ }
311+
312+ const returnKeyId = ' id'
300313// Insert and return an array of products objects
301314const products = await database
302315 .buildTable (' products' )
303- .insertAndGet ({ name: ' iPhone 13' })
316+ // You can set returnKey here too, this way it will insert the product
317+ // and then find the products by the returnKey value, in this case, the id
318+ // WARN - Remember, this is a SQL feature only and will not take effect in MongoDriver
319+ .insertAndGet ({ name: ' iPhone 13' }, returnKeyId )
304320
305321// WARN - buildTable method needs to be called only one time before the connection is stabilished.
306322// when you call buildTable it saves in the Driver instance the table that you are working on.
@@ -336,10 +352,26 @@ const productsPaginated = await database.forPage(page, limit)
336352``` ts
337353const productIds = await database .insert ([{ name: ' iPhone 10' }, { name: ' iPhone 11' }])
338354
339- // Be carefull with update, remember to always use where
355+ // WARN - ONLY FOR SQL
356+ {
357+ // When Database update the data he will always return an array of ID.
358+ // But you can change this behavior setting the returnKey value
359+ const returnKey = ' name'
360+ const productNames = await database
361+ .buildTable (' products' )
362+ .update ([{ name: ' iPhone 13' }], returnKey )
363+
364+ // The returnKey can be defined only in SQL Drivers because Mongo always returns the _id by default
365+ }
366+
367+ const returnKeyId = ' id'
368+ // WARN - Be carefull with update, remember to always use where
340369const productsUpdated = await database
341370 .buildWhereIn (' id' , productIds )
342- .updateAndGet ({ name: ' iPhone X' }) // or updateAngGet('name', 'iPhone X')
371+ // You can set returnKey here too, this way it will update the product
372+ // and then find the products by the returnKey value, in this case, the id
373+ // WARN - Remember, this is a SQL feature only and will not take effect in MongoDriver
374+ .updateAndGet ({ name: ' iPhone X' }, returnKeyId ) // or updateAngGet('name', 'iPhone X', returnKeyId)
343375
344376console .log (productsUpdated ) // [{ id: 1, name: 'iPhone X', quantity: 0 }, { id: 2, name: 'iPhone X', quantity: 0 }]
345377```
0 commit comments