Questions tagged [knex.js]

Knexy.js brings together the best of query building capabilities for multiple databases like Postgres, MySQL, SQLite3, Oracle, and MS SQL Server. With a focus on flexibility, portability, and user enjoyment, it offers an array of unique features. Embrace traditional node style callbacks or indulge in its promise interface to ensure cleaner asynchronous flow control. Benefit from its power-packed query and schema builders, transaction support, connection pooling, and consistent response formats across various query clients and dialects.

"Exploring the benefits of using nested mapping for res.json() in an Express application

I have been developing an express application (server-side) that offers movie information to users, and I am attempting to send a JSON response in the following format: { "title": "Star Trek: First Contact", "year": 1996, ...

One scenario where the KnexJS Raw Method fails to function

During my work on a project with KnexJS, I have been utilizing the .raw() method successfully. However, I recently encountered an issue where this method was not being properly integrated into the SQL query, resulting in a syntax error at end of input. 'u ...

Enhancing a knex/bookshelf model with custom functions in a node/express application

I've defined my model like this: const User = db.Model.extend({ tableName: 'users', hasSecurePassword: true }); module.exports = User; With this setup, I can perform actions such as const User = require("../models/user"); ...

Knex has encountered a deadlock issue and has detected it

There is a function that reduces the stock in a database, but Knex is showing a 'Deadlock Detected' error when attempting to subtract quantities of 2 different items. This code contains loops to manage this issue. const updateOrder = (req, res, ...

Save the output of a knex query to a variable

I'm struggling to assign the result of a select query using Knexjs to a variable. Here is my code: function getAllCategories() { let categories; categories = database.from("categories").select("category").then(function (rows) { for (let row of ro ...

Using Bookshelf, Knex, and MySQL to store information about a collection of items

I'm facing a dilemma when it comes to using the Bookshelf model to insert data into the database in this particular scenario: The libraries I am working with include knex, bookshelf, express, body-parser, and a MySQL database In my database, there i ...

What are some strategies for stopping Knex.js from executing a query object upon return from an asynchronous function?

My node.js backend utilizes Knex.js to construct dynamic DB queries based on various inputs. The challenge I'm facing is handling asynchronous processing of certain inputs. When returning a knex query object from an async function or a Promise resolve ...

Is it possible to have nullable foreign keys using objectionjs/knex?

It seems like I'm facing a simple issue, but I can't quite figure out what mistake I'm making here. I have a table that displays all the different states: static get jsonSchema() { return { type: 'object', properties: { id: { type ...

Leveraging orWhere in the bookshelf JavaScript object

I encountered an issue while using bookshelf js to create a query. When implementing orWhere in the query, I received an error message. An error occurred stating 'Object has no method 'orWhere'." Below is the code snippet that led to thi ...

Utilize knex.js and TypeScript to create queries with specific conditions

I am trying to create a dynamic query that will include a where clause based on whether the variables name and/or city are passed. While I couldn't find a specific method for this in the documentation, I attempted to add the where clauses directly to the ...

Verifying an array of objects in NodeJS

Here is an example of the array I am working with: settings: [ { key: 'maxImageSize', value: '512' }, { key: 'maxFileSize', value: '2048' }, { key: 'searchResultsLimit', value: '10' ...

Tips for choosing a DB Expression as a value in knex/Bookshelf

I am attempting to run the following query using knex.js and MySql SELECT m.id, TIME(date_created) AS `timestamp`, u.username, m.`message` FROM `messages` AS m INNER JOIN users AS u ON u.id = m.user_id WHERE m.game_id IS NULL AND m ...

What is the most efficient way to retrieve 10,000 pieces of data in a single client-side request without experiencing any lag

Whenever I retrieve more than 10 thousand rows of raw data from the Database in a single GET request, the response takes a significant amount of time to reach the client side. Is there a method to send this data in smaller chunks to the client side? When ...

Executing Postgresql procedures using Knex in a Node.js environment

Attempting to execute a stored procedure located in the public schema with: const schema = await knex.raw("call create_schema(?, 'col1', 'col2', 'col3', 'col4', 'col5', 'col6')", schema_name); The purpose of this procedure is to establis ...

passport.authenticate() does not return a defined user

I am facing an issue with the login functionality of my application. While the register function works fine, I encounter a "501-not implemented" error when trying to log in. Here's a snippet from my code: const passport = require('passport') router.post( ...

What is the best method for utilizing a function within a where clause with Knex?

Essentially, I am trying to figure out how to construct this query using Knex: SELECT * FROM usr_info WHERE login = ? AND password = PASSWORD(?) For instance: knex('usr_info') .where({ 'login': login, 'password': password // <-- include a ...

Tips for linking promises in knex with the ON CONFLICT clause?

Currently, I have two tables in my database named 'temp_users' and 'ratings' TABLE 1 (temp_users) temp_user_id(primary key) | ip_address | total_ratings ----------------------------------------- | ...

The promise remains unresolved even after calling knex.destroy()

I've been making progress with my understanding of Promises, but I'm puzzled by the behavior of knex in Node.js. When I successfully receive a query and log it out, everything seems fine. However, when I run node filename.js The process doesn't quit an ...

Experiencing an ER_CON_COUNT_ERROR is common when the default max pool of Knex.js is exceeded due to an overwhelming

We currently have 30 DigitalOcean droplets, each dedicated to a web CRM user. They all share the same MySQL database using knex.js. However, with a few additional users, we are encountering some errors: "ER_CON_COUNT_ERROR: Too many connections" ...

Executing a Knex RAW MySQL query to insert new records into a database table

As someone new to working with MySQL, I have previously used PSQL in a similar manner. However, the following code is generating an error. return await db .raw( `INSERT INTO users(firstName, lastName, email, ...

I am facing difficulties accessing my PG database on pSequel and establishing a connection with my Node backend

I recently started working on my first Node.js/Express.js API with a PostgreSQL database. After setting up the database and creating some tables last night, I encountered an issue today where I couldn't connect it to my backend. When trying to access it in ...

Guide on how to efficiently insert JSON data into three different tables and retrieve the data from two tables in JSON format using knex and express.js

How to store JSON data in multiple tables and extract specific table data using knex and express.js The task at hand involves inserting data into three separate tables - login, user, and profile. Following this insertion, we need to retrieve the user and ...

Encountering a faulty handshake or ECONNRESET error connection in Azure Mysql while using

Issues with connecting to a mysql database hosted in Azure using an express.js app and KNEX have been troublesome. While I can successfully connect to the database from the console command or mysql workbench, my node app fails to do so. The connection ob ...

Postgres Array intersection: finding elements common to two arrays

I'm currently developing a search function based on tags, within a table structure like this CREATE TABLE permission ( id serial primary key, tags varchar(255)[], ); After adding a row with the tags "artist" and "default," I aim ...

Knejx Js is the embodiment of guarantees

I am trying to figure out how to make this function work. I only receive a promise as the output. codeProducts.forEach((code, index) => { const qt = app.db('products').where('code', code).first().then(result => result.quantity) data[ind ...

Combining Multiple Tables Using Knex SQL Joins and Storing the Result in an Array

At the moment, I'm utilizing Knex to carry out queries on a MSSQL database. In my schema, there is a table named "Meals" which has the following columns: Id Additionally, there is also a table named "Vegetables" with the following columns: Id Meal (whi ...

Is there a way to retrieve data from three different Bookshelf.js models in a single query?

Three tables are in my database: User, UserDrink, and VenueDrink Here is a preview of the sample data: User id | name | gender | -------------------- 1 | John | male | 2 | Jane | female | UserDrink id | count | user_id | venue_drink_id 1 | 3 | ...

Tips for incorporating 'and' in the 'on' clause of 'join' in knex.js

I need assistance implementing the following SQL code in knex.js: select c.id,c.parent_id,c.comment,u.username,c.postid from comments as c join post_details as p on (p.id = c.postid and c.postid=15)join users as u on (u.id = c.userid); I attempt ...

Guide: Leveraging the Knex object in a separate file

How can I effectively utilize the knex db object across multiple files? As an illustration In my main index.js file: const app = require("express")(); const cors = require("cors"); const bodyParser = require("body-parser"); const user = require("./route ...

Could not establish a connection to ClearDB while utilizing Proximo services

I am currently utilizing Proximo on Heroku to run my Node.js application in order to obtain a static IP address for outbound traffic. However, since implementing this setup, I have encountered an issue where the MySQL connection is timing out and refusing ...

Struggling to successfully update columns in postgresql using knex.js

Encountering a very peculiar issue during updates where I don't receive any response - no errors, warnings, success messages - it's as if nothing is changing. The request seems to be stuck in an infinite loop, always loading. I am using knex.js f ...

The API call for /api/users/create was resolved without a response, which could potentially lead to requests getting stuck. This issue was detected in

I've developed an API endpoint to manage user account creation within my Next.js application, utilizing knex.js for handling queries. Despite this, I keep encountering the following error: API resolved without sending a response for /api/users/create ...

Utilizing Sinon to Stub Chained "whereIn" Functions in Objection.js

Need help stubbing a chained knex query with Sinon. Here is the query: const result = await TableModel .query() .whereIn('id', idList) .whereIn('value', valueList); Usually, I use a custom helper function that stubs each method ...