Questions tagged [knex.js]

0 votes
1 replies
Knex, Postgres, and STRING_ARRAY: getting different results
I was testing out a query here using STRING_ARRAY: http://sqlfiddle.com/#!17/952405/1 Also here: SELECT to_char(workshop_date, 'YYYY-MM-DD')...
0 votes
2 replies
NodeJS - Cannot set Headers after they are sent to the client
So I've searched around and found out that to fix the said issue, I have to return after sending a response. But my problem is, even though I hav...
asked 1 month ago
0 votes
2 replies
construct inner join with AND using Knex.js in Node application
Is ti possible to write a join similar to this SQL join using knex.js in a Node application? INNER JOIN member_staff ON members.id = member_staf...
asked 1 month ago
1 votes
1 replies
Ending response when knex throws an error using async/await
I'm getting "Cannot set headers after they are sent to the client" this error in my api. I understand that I'm sending response back multiple tim...
1 votes
1 replies
Can I chain a Knex Raw command?
I'm using knex.raw to insert rows with Postgres ON CONFLICT... I want to insert multiple row like batchInsert. How can I chain raw statements?...
asked 1 month ago
0 votes
2 replies
Knex is returning Deadlock Detected
So I have this function that will decrease a stock on the database, the problem is, Knex is returning a 'Deadlock Detected' if I have to subtract...
asked 1 month ago
0 votes
2 replies
How to optimize promises to avoid callback/promise hell
I'm using knex.js for my database and I have a query that depends on the previous query. Example: user table | username(pk) | first_name | la...
asked 1 month ago
0 votes
0 replies
How to conditionally omit leftJoin operations in postgresql objectionjs?
I have a situation where i need to use some query but omit some leftJoin-s on special condition . I want to write as much DRY as it is possible...
asked 1 month ago
0 votes
1 replies
How to count specified rows in another table
I am using Knex.js and want to count specific rows in the bans table. There is an users table, where two ip addresses are set. current_ip and rem...
asked 1 month ago
0 votes
1 replies
unrelate() doesn't seem to be changing or deleting the join table
UserTagAnswer model: answer: { relation: Model.ManyToManyRelation, modelClass: sails.config.models.UserTagAnswerOptions, join: {...
asked 1 month ago
1 votes
1 replies
How do you insert a reference to a model without creating it?
I have model A that can have one or more rows of model B affiliated with it. The relation only has to go one way. I ran: result = await A.query...
asked 1 month ago
0 votes
0 replies
Doing action on knex.js batchInsert with a PostgresSQL database
I am trying to use knex.js batchInsert and when there is a conflict based off an unique index I would like the action to be "Do nothing". I have...
asked 1 month ago
0 votes
1 replies
Prevent knex database connection pool from closing when idle
I am using Knex.js to handle my connections to database. I am trying to prevent connection pool from destroying the connections that were idle....
0 votes
1 replies
knex transaction is not working with async await
im workin with knex and node, when im trying to use transaction its not working and trhowing following error Unhandled rejection TypeError: conta...
asked 2 months ago
4 votes
1 replies
Where and when to use knex.destroy?
I'm confused on where to use knex.destroy() in my Node API. If I don't use knex.destroy() after I open the connection to make a call, the conne...
asked 2 months ago
0 votes
0 replies
knex migration cause early mocha test fail
I am writing some mocha tests where I initialize the postgress DB using knex in the beaforeEach(), afterEach() and after() hooks. Here is an exa...
asked 2 months ago
0 votes
0 replies
How to properly close connection pools on express finish request
My Express App creates many knex connections to databases dynamically, since there are many projects and different databases. Recently Im facing...
asked 3 months ago
0 votes
1 replies
How to access the transaction of the current context while extending QueryBuilder class in Knex
Im trying to extend the QueryBuilder of Knex.js. I want to modify the delete() method in order to delete the child elements of my Objection.js Mo...
0 votes
0 replies
How to use “ALTER TABLE CHANGE” in knexjs for rename and reorder column?
I have a User table with these fields (id,userId,referrerUserId). I need change table structure to this (id,referrerUserId,userName). In sql quer...
asked 2 months ago
0 votes
0 replies
How to delete rows from one table after innerJoin using Objection.js and Knex.js?
I am new in postgresql and having trouble to refactor some code which is written by me . The code reviewer didn't accept my solution , thinking t...
asked 2 months ago
0 votes
1 replies
What is the default version used by Knex.js for the mysql client when no value specified
The Knex.js documentation allows for a version to be set when using a client, in my case I'm using mysql, something like this: client: 'mysql...
asked 2 months ago
2 votes
1 replies
how to repeat the id for the length of an array in nodeJS and knexJS
I want to add an array of items with the same orderId, so I need to have the orderId repeated for the length of the array, how do I do that? My...
asked 3 months ago
2 votes
1 replies
how to repeat the id for the length of an array in nodeJS and knexJS
I want to add an array of items with the same orderId, so I need to have the orderId repeated for the length of the array, how do I do that? My...
asked 3 months ago
0 votes
0 replies
knex.js hardcoded column value
I have a SQL query as below select 'Dept', dept_id from departments Column 1 is hardcoded value 'Dept' Column 2 is dept_id from table departmen...
asked 2 months ago
0 votes
0 replies
ObjectionJs andWhereRaw is not a function with postgres and nodejs
I am trying to understand why I'm getting a TypeError: ____.andWhereRaw is not a function using ObjectionJs with Postgres and how to resolve this...