You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pulling an object literal into the function also doesn't work
exportasyncfunctiongetAllOrders(opts={},whereClause=''){// Combine the options passed into the function with the defaults/** @type {OrderCollectionOptions} */letoptions={
...{order: 'asc',page: 1,perPage: 20,sort: 'id'},
...opts};console.log(options);->RESULT: {order: undefined,page: '2',perPage: 30,sort: undefined}constdb=awaitgetDb();returnawaitdb.all(sql`SELECT ${ALL_ORDERS_COLUMNS.join(',')}FROM CustomerOrder${whereClause}ORDER BY ${options.sort}${options.order}LIMIT ${options.perPage}OFFSET ${options.page*options.perPage}`);}
When I log options inside the function I get the following:
exportasyncfunctiongetAllOrders(opts={},whereClause=''){// Combine the options passed into the function with the defaults/** @type {OrderCollectionOptions} */letoptions={
...DEFAULT_ORDER_COLLECTION_OPTIONS,
...opts};console.log(options);->RESULT: {order: undefined,page: '2',perPage: 30,sort: undefined}constdb=awaitgetDb();returnawaitdb.all(sql`SELECT ${ALL_ORDERS_COLUMNS.join(',')}FROM CustomerOrder${whereClause}ORDER BY ${options.sort}${options.order}LIMIT ${options.perPage}OFFSET ${options.page*options.perPage}`);}
I haven't been able to fix it though.
[edit]
This one worked for some reason
exportasyncfunctiongetAllOrders(opts={},whereClause=''){// Combine the options passed into the function with the defaultsconstoptions2={
...{order: 'asc',page: 1,perPage: 20,sort: 'id'},
...{page: '2',perPage: 30}};console.log(options2);->RESULT: {order: 'asc',page: '2',perPage: 30,sort: 'id'}constdb=awaitgetDb();returnawaitdb.all(sql`SELECT ${ALL_ORDERS_COLUMNS.join(',')}FROM CustomerOrder${whereClause}ORDER BY ${options2.sort}${options2.order}LIMIT ${options2.perPage}OFFSET ${options2.page*options2.perPage}`);}
The text was updated successfully, but these errors were encountered:
EddyVinck
changed the title
Object merge is not working due to scope issue (probably)
Object merge is not working
Aug 9, 2018
https://github.com/mike-works/sql-fundamentals/blob/master/src/data/orders.js#L40-L43
I tried it outside of the function and the result is as expected.
Pulling an object literal into the function also doesn't work
When I log
options
inside the function I get the following:I haven't been able to fix it though.
[edit]
This one worked for some reason
The text was updated successfully, but these errors were encountered: