JavaScript Objection js update with increments +1

How i can update value in database using objection ? My SQL query works perfect.

UPDATE "freePlace"
SET number = number-1
WHERE   date >= '2017-10-20'   AND date <= '2017-10-30' AND "idObject" = '1'

My objection code:

FreePlace.query().patch({number:number+1}).where('date', '>=', startDate)
  .andWhere('date', '<=', endDate)
  .andWhere('idParking', '=', parkingId)

Problem is in patch({number:number+1}) how i need do this ?

Answer:1

Looks like you need to use ref(). The code as you have it won't know where to get the value of "number+1".

How about this?

FreePlace.query().patch({number:ref('number')+1})
  .where('date', '>=', startDate)
  .andWhere('date', '<=', endDate)
  .andWhere('idParking', '=', parkingId)

See this example from objection.js docs:

Person
  .query()
  .patch({
    age: Person.query().avg('age'),
    firstName: Person.raw("'Jenni' || 'fer'"),
    oldLastName: ref('lastName')
  });
Answer:2

I have a ng-repeat div, and inside the div have select control. This code produces parse error: <select name="qty" ng-model="Qty"> <option ng-repeat="v in [1,2,3,4,5,6,7,8,9,10]" ...

I have a ng-repeat div, and inside the div have select control. This code produces parse error: <select name="qty" ng-model="Qty"> <option ng-repeat="v in [1,2,3,4,5,6,7,8,9,10]" ...

I'm trying to use a modal triggered from the ion-header-bar to overlay on top of a google map. When I click 'login' it slides in a black screen. I've heard of including bootstrap can cause the ...

I'm trying to use a modal triggered from the ion-header-bar to overlay on top of a google map. When I click 'login' it slides in a black screen. I've heard of including bootstrap can cause the ...

  1. ionic modal slide right
  2. ionic modal slide up
  3. ionic modal-slide-in
  4. ionic modal animation slide-in-down

How can I handle destructuring a nested object that might have an undefined internal object? For example. I have a xhr req that returns {person: user: {}} For example: const xhrResponse = {person: ...

How can I handle destructuring a nested object that might have an undefined internal object? For example. I have a xhr req that returns {person: user: {}} For example: const xhrResponse = {person: ...

  1. object destructuring nested
  2. destructuring nested object javascript
  3. destructuring nested object es6
  4. destructuring nested object js
  5. destructuring nested objects undefined
  6. destructure nested object react
  7. destructuring assignment nested object
  8. js object destructuring nested
  9. javascript object destructuring nested
  10. es6 object destructuring nested

I have multiple DOM elememts. When each one becomes visible within the window then I fire an animation on that element. Each element registers the window scroll event to the same event handler, ...

I have multiple DOM elememts. When each one becomes visible within the window then I fire an animation on that element. Each element registers the window scroll event to the same event handler, ...