knex.js

knex: what is the appropriate way to create an array from results?

十年热恋 提交于 2021-02-07 01:33:40
问题 I have an endpoint that joins the user and user_emails table as a one-to-many relationship (postgresql). It look as follows. router.get('/', function (req, res, next) { db.select('users.id', 'users.name', 'user_emails.address') .from('users') .leftJoin('user_emails', 'users.id', 'user_emails.user_id') .then(users => res.status(200).json(users)) .catch(next) // go to error handler }); However, this will return a new document for each email address. What I want is an array of documents that

Trying to get a specific user using Axios get request not working. Should be a minor fix?

我是研究僧i 提交于 2021-01-29 14:23:43
问题 I figured it would work similarly to my delete request since it targets a specific user(delete request works perfect), so I passed an id as well to my get request. I logged the response of the request and I am given the error from my catch block in the file where I defined my sql queries using Knex, so i believe something is wrong with my sql query?. In the logged response I can also see the id of the user im wanting to display which is a good sign, so I think it has to be a minor error

Server in docker container unable to connect to postgres database in another docker container

情到浓时终转凉″ 提交于 2021-01-29 13:08:05
问题 I have a node server that's trying to connect to a postgres database using knex. Both are in docker containers with the same custom network. I keep getting ECONNREFUSED errors. I've poked around in the database container and I see that my DB ( test_db ) has been created by psql but it has no permissions. After giving root permissions, I'm still getting the same issues. I've tried removing the volumes with docker-compose down -v but still no luck. I've also tried removing knex and just using

how to pass output parameter to ms-sql stored procedure using knex

匆匆过客 提交于 2021-01-29 05:01:34
问题 how to pass output parameter to ms-sql stored procedure using knex Query builder. we are using Knex in node js to call MS-SQL raw query and stored procedure. In MS-SQL, we can pass both IN and OUTPUT parameter in stored procedure. Now, i am stuck, how to pass output parameter to ms-sql stored procedure. Procedure parameter is like this : exec sp_procedurename 'username',@RecCount OUTPUT,'',1,30,'' 回答1: node-mssql driver has pretty custom syntax for that (https://github.com/tediousjs/node

How to add two bind params in knex?

时光毁灭记忆、已成空白 提交于 2021-01-05 10:58:59
问题 I'm traying to select something from database and I have to use 2 bind params. With one param it works but with two i get this error "Undefined binding(s) detected when compiling RAW query" error and "Expected 1 bindings, saw 2" in nodejs console. How to use 2nd bind param? Code that works: knex.with('with_alias', knex.raw('select * from "lyrics" where "for_id" = "1" and "var" = ?', var)).select('*').from('with_alias') I also tried but it didn't worked knex.with('with_alias', knex.raw('select

How to add two bind params in knex?

妖精的绣舞 提交于 2021-01-05 10:58:26
问题 I'm traying to select something from database and I have to use 2 bind params. With one param it works but with two i get this error "Undefined binding(s) detected when compiling RAW query" error and "Expected 1 bindings, saw 2" in nodejs console. How to use 2nd bind param? Code that works: knex.with('with_alias', knex.raw('select * from "lyrics" where "for_id" = "1" and "var" = ?', var)).select('*').from('with_alias') I also tried but it didn't worked knex.with('with_alias', knex.raw('select

Knex.js: Create table and insert data

前提是你 提交于 2020-12-30 08:25:10
问题 Given that I have a Knex.js script like this: exports.up = function(knex, Promise) { return knex.schema.createTable('persons', function(table) { table.increments('id').primary(); table.string('name').notNullable(); }); }; which currently creates a table. How do I add subsequent insert statements to this script? What I want to do is add a line like this (or similar): knex.insert({id: 1, name: 'Test'}).into('persons') I'm not sure I understand how this promise-based approach works. Am I

Knex.js: Create table and insert data

霸气de小男生 提交于 2020-12-30 08:24:33
问题 Given that I have a Knex.js script like this: exports.up = function(knex, Promise) { return knex.schema.createTable('persons', function(table) { table.increments('id').primary(); table.string('name').notNullable(); }); }; which currently creates a table. How do I add subsequent insert statements to this script? What I want to do is add a line like this (or similar): knex.insert({id: 1, name: 'Test'}).into('persons') I'm not sure I understand how this promise-based approach works. Am I

Trying to connect to Mssql server via knex

我是研究僧i 提交于 2020-12-13 03:18:57
问题 I'm trying to connect to a remote database with knex but I get this error: "tedious deprecated The default value for options.encrypt will change from false to true . Please pass false explicitly if you want to retain current behaviour. at node_modules\mssql\lib\tedious.js:212:23 Unhandled rejection ConnectionError: Failed to connect to 151.80.119.227,14831:1433 - getaddrinfo ENOTFOUND 151.80.119.227,14831" I can connect via Microsoft sql server management studio with same host, user, password

Knex silently converts Postgres timestamps with timezone and returns incorrect time

纵然是瞬间 提交于 2020-12-08 06:58:09
问题 I have a table in my psql database with a "trigger_time" column of type "TIMESTAMP WITH TIME ZONE DEFAULT now()" I data in the row is this 2018-06-27 15:45:00-03 . When running from psql console SELECT trigger_time AT TIME ZONE 'UTC' FROM tasks WHERE task_id = 1; this query returns "2018-06-27 18:45:00". Similarly when I run SELECT trigger_time AT TIME ZONE 'America/Glace_Bay' FROM tasks WHERE task_id = 1; I get 2018-06-27 15:45:00 Using knex.raw("SELECT trigger_time AT TIME ZONE 'America