Combining Update and Select Operations in Knex JS in a Single Query

With Knex JS - Can all elements from the row being updated be retrieved in a single query that combines both update and select operations? Currently, only the id of the updated row is returned by the update operation.

let query = await knex('items').select('id', 'customerId', 'itemId').where('id', id).update({ inactive: true })

Appreciate your help!

Answer №1

When working with postgres, remember to utilize the .returning() method.

const query: any = await knex('items')
  .returning('id', 'customerId', 'itemId')
  .where('id', id)
  .update({ inactive: true });

If you need more information, check out the Knex documentation here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Getting the user's name and country using `auth().createUserWithEmailAndPassword` is a simple process

Hey there fellow developers. I'm fairly new to react native and I'm trying to implement firebase authentication for a project. However, I'm stuck on how to include user name and country when using the standard auth().createUserWithEmailAndPa ...

Make sure to keep the server updated with the current status of the page, indicating whether it is

I am currently developing a Phonegap app that allows users to chat with each other and receive push notifications if they are not active in the chat window. I am using PHP and sending messages via AJAX, but I am struggling to determine if the receiver is ...

An issue has occurred: Cannot access the properties of an undefined object (specifically 'controls')

I encountered an error message stating "TypeError: Cannot read property 'controls' of undefined" in the code that I am not familiar with. My goal is to identify the source of this error. Below is the HTML code snippet from my webpage: <div ...

`Express.js Controllers: The Key to Context Binding`

I'm currently working on a project in Express.js that involves a UserController class with methods like getAllUsers and findUserById. When using these methods in my User router, I have to bind each method when creating an instance of the UserControlle ...

Error message: "PHP code encountering issues with the MySQL count function"

I am attempting to calculate the number of rows in a gallery table using the following code: function count_product_gallery($Product_ID) { global $kapcs; $count_sql = "SELECT COUNT (gallery_id) AS ennyi_kep FROM gallery WHERE gallery_termek_id = ...

Mapping distinct JSON keys to button components using Javascript/React

I am dealing with the JSON data below: [ {"location":"2034","type":"Residential","price":400000,"address":"123 Fake Street","suburb":"Maroubra","historical_DAs&q ...

Populating dropdown menu with data from redux state upon component mounting

I am new to working with react-redux and have successfully implemented dependent dropdown functionality in a react component (Country => State => City). My goal now is to dynamically update the dropdown values based on data received from the redux s ...

Transferring information between two Vue components using a variable declared in the main JavaScript file

In my project, I am working with two separate Vue files - let's say 1.vue and 2.vue - along with a main JS file. Within my main.js file, there is a variable xyz under the window.App data method. I am looking to utilize this variable as a shared data ...

Ways to empty an angularJS array

let itemList = ['X', 'Y', 'Z']; Even though the array is cleared, the user interface does not reflect the change. itemList = []; This method solves the issue. But why? itemList.length = 0; ...

It is not possible to make any further changes to the scene in THREE.js

Here is an example you can check out: Example Link I noticed that in newer versions of THREE.js, if the render function is called before adding additional objects to the scene, those objects will not be visible even with multiple subsequent calls to rend ...

Tips for effectively showcasing the counter outcome amidst the increase and decrease buttons

Currently, I am in the process of learning Angular and have created a component called quantity-component. Within the quantity-component.component.html file, I have implemented 2 buttons for increment (denoted by +) and decrement (denoted by -). The decrem ...

Select a specific date range from a form and export CSV file containing MySQL data within that range

I have successfully implemented a database CSV export functionality, but now I am looking to allow the user to specify a date range for the export process. Below is the HTML section that handles the date selection (date format: mm/dd/yyyy): <form act ...

Looping through arrays within objects using NgFor in Angular 2/JavaScript

I have a custom object with data that I am iterating through using ngFor. Within this object, there is an array component that I also want to iterate through in a <li></li>. Currently, the output appears as one complete string within each < ...

Update the Div content with animation on the change

I have mastered the art of refreshing a DIV element, but now I am looking to take it up a notch by incorporating an animation into the transition. The idea is that when a user approves an offer, the div containing a series of boxes should elegantly 'm ...

Each time forEach is called, it increments the previous result by 1

My service returns a response containing the following data: {"id":157336,"results":[ {"id":"53db3c790e0a26189a000d09","iso_639_1":"en","key":"ePbKGoIGAXY","name":"Trailer 3","site":"YouTube","size":1080,"type":"Trailer"}, {"id":"550df44b925141355 ...

Invoking res.download() in the Express framework

It's puzzling why this issue is occurring, and it's quite frustrating. I was expecting the file to be downloaded in line with the guidelines provided in the Express documentation. Below is the code snippet I am using: //within React (App.js) ...

Having trouble getting the group hover animation to function properly in Tailwind CSS

Just starting out with tailwind css and running into a little issue. The hover animation I'm trying to apply isn't working as expected in this case. Instead of seeing the desired animated background when hovering over the group, it seems the back ...

Fetch operates based on the specified categoryId

Hey there, I'm currently in the process of learning JS and trying to fetch data from an API. I've successfully fetched all the work from api/works and displayed them in a div. Now, I'm looking to create 3 buttons that represent 3 categories ...

Can you explain the inner workings of the service hierarchy within this Angular 2 application?

As a newcomer to Angular 2, I have a question regarding services. In the main view (associated with the app.component.ts class), I am faced with the following scenario: <div class="container"> <div class="row"> <div class="col-xs-12 ...

Guide on parsing and totaling a string of numbers separated by commas

I am facing an issue with reading data from a JSON file. Here is the code snippet from my controller: myApp.controller("abcdctrl", ['$scope', 'orderByFilter', '$http', function ($scope, orderBy, $http) { console.log('abc ...