knex.js

Unhandled promise rejection - Error: Can't set headers after they are sent

前提是你 提交于 2021-02-19 05:42:08
问题 I am new to node, and I have a simple situation, where I am posting to an endpoint on a node/express app. The issue is that I get: POST /api/v2/user 500 25.378 ms - 54 (node:19024) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Can't set headers after they are sent. (node:19024) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit

knex migration fail, but doesnt revert changes

六眼飞鱼酱① 提交于 2021-02-11 13:54:07
问题 I want to use knex in my ts project. migration looks like this: export async function up(knex: Knex): Promise<any> { return knex.schema.createTable('first_table', (t) => { t.integer('first_table_id').primary(); }).createTable('second_table', (t) => { t.integer('id'); // simulation sql error, duplicate in this case. t.integer('id'). }) } Migration already fail. I wait transaction rollback for all changes but i have successfully created first_table. I do not understand something or Knex behaves

Error: Access denied for user ''@'localhost' (using password: NO)

只谈情不闲聊 提交于 2021-02-10 17:47:01
问题 I'm trying out db migrations with MySQL and Knex. When I run the command knex migrate:latest , I get ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO) I've tried adding a password on the codebase (to '123' and 'NO'), though what confuses me most is that even as I have user: "root" in my database file, the error gives an empty string as the user... I share what I imagine are the pertinent files: // mysql_db.js const knex = require('knex')({ client: 'mysql',

Undefined db connection with knex

拈花ヽ惹草 提交于 2021-02-08 04:49:11
问题 I am executing the following script, node acl.js : acl.js require('dotenv').config() const _ = require('lodash'); const buckets = require('./buckets'); const knex = require('../src/config/db'); //HERE I am getting the ERROR var downSql = 'DROP TABLE IF EXISTS "{{prefix}}{{meta}}";'+ 'DROP TABLE IF EXISTS "{{prefix}}{{resources}}";'+ 'DROP TABLE IF EXISTS "{{prefix}}{{parents}}";'+ 'DROP TABLE IF EXISTS "{{prefix}}{{users}}";'+ 'DROP TABLE IF EXISTS "{{prefix}}{{roles}}";'+ 'DROP TABLE IF

Decimal value in Postgresql returned as String in Node.js

回眸只為那壹抹淺笑 提交于 2021-02-07 19:09:22
问题 When I run a query to my postgresql database on a node.js server, the value that I am getting is of variable type string when in fact it is a decimal in the postgresql database. I am not sure why my decimals or even bigInts are returning as type strings. I am using knex as my ORM if that makes a difference. So far what I have read online is not very clear about what to do, and it seems as if this happens automatically to preserve precision??? What is the best work-around for this? Is it best

Strongly-typed database access with Node.JS and TypeScript

半腔热情 提交于 2021-02-07 02:48:32
问题 When we use C# , we can access our database in a strongly-typed manner using Code-First approach: public class Blog { public int BlogId { get; set; } public string Name { get; set; } public virtual List<Post> Posts { get; set; } } ... public class Database : DbContext { public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; } } var db = new Database() var blog = new Blog { Name = "My new blog", BlogId = 1 }; db.Blogs.Add(blog); db.SaveChanges(); // save object to database

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

南楼画角 提交于 2021-02-07 01:53: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

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

倖福魔咒の 提交于 2021-02-07 01:46:18
问题 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

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

孤街醉人 提交于 2021-02-07 01:40:34
问题 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

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

风流意气都作罢 提交于 2021-02-07 01:40:16
问题 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