knex.js

Update enum column types in knex migration

a 夏天 提交于 2020-08-03 04:20:08
问题 I'm looking to write a migration string to add a new string to the enum column type. I'm trying to add gamma to the service column. I tried with this code below. This collides because the table and the column already exists. const table = 'user_associations' export function up (knex, Promise) { return knex.schema.table(table, function (table) { table.enu('service', ['alpha', 'beta', 'gamma']).notNullable() }) } export function down (knex, Promise) { return knex.schema.table(table, function

Bad handshake or ECONNRESET Azure Mysql Nodejs

北城以北 提交于 2020-06-28 09:10:48
问题 Similar issues have been reported, but I can't work around with there solutions. I have an express.js app using KNEX to connect to a mysql database hosted in Azure. I can connect to the DB perfectly from console command or mysql workbench. However, no way to achieve the same from my node app. My connection object is the same though: config.knex = require('knex')({ client: 'mysql', connection: { host: 'wineserver.mysql.database.azure.com', user: 'BurgerAndGreenBeans@wineserver', password:

Bad handshake or ECONNRESET Azure Mysql Nodejs

佐手、 提交于 2020-06-28 09:10:14
问题 Similar issues have been reported, but I can't work around with there solutions. I have an express.js app using KNEX to connect to a mysql database hosted in Azure. I can connect to the DB perfectly from console command or mysql workbench. However, no way to achieve the same from my node app. My connection object is the same though: config.knex = require('knex')({ client: 'mysql', connection: { host: 'wineserver.mysql.database.azure.com', user: 'BurgerAndGreenBeans@wineserver', password:

How is Node.js Knex similar/different to Sequelize?

偶尔善良 提交于 2020-06-25 08:40:07
问题 The answer I got from an IRC channel: Sequelize is an ORM that includes some query builder stuff; Knex is just a query builder, not an ORM. ORMs don't actually fit very well in many use cases, it's easy to run up against the limits of what they can express, and end up needing to break your way out of them. But that doesn't really explain the pros and cons of each. I am looking for an explanation, and possibly a simple example (use case) highlighting those similarities / differences. Why would

Alias a table in Knex

淺唱寂寞╮ 提交于 2020-06-25 07:27:06
问题 I have a SQL query that refers to the same table twice, and I need to alias the table to two separate aliases. I can't quite figure out how to compose this with Knex. There's a 'Words' table and a 'Users' table. The Words table has two foreign keys, 'author_id' and 'winner_id', referencing the Users table's 'id' column. Here's the SQL I'm trying to compose in Knex: SELECT w.*, ua.name, uw.name FROM Words AS w INNER JOIN Users AS ua ON w.author_id = ua.id LEFT JOIN Users AS uw ON w.winner_id =

How can I mock a fake database for when unit testing against Knex?

巧了我就是萌 提交于 2020-06-24 22:21:34
问题 I've been using Knex successfully to connect to a backend database. But I want to be able to unit test my code. Is there a way to mock the database connection? I've tried using proxyquire but I can't seem to get it to work. The problem seems to be with the way Knex is initialized. var knex = require('knex')({ client: 'mysql', connection: {} }); I setup knex to be mocked in my unit test. myService = proxyquire('../app/myService', { 'knex': knexProxy }); My service includes knex. var knex =

How can I mock a fake database for when unit testing against Knex?

自古美人都是妖i 提交于 2020-06-24 22:21:11
问题 I've been using Knex successfully to connect to a backend database. But I want to be able to unit test my code. Is there a way to mock the database connection? I've tried using proxyquire but I can't seem to get it to work. The problem seems to be with the way Knex is initialized. var knex = require('knex')({ client: 'mysql', connection: {} }); I setup knex to be mocked in my unit test. myService = proxyquire('../app/myService', { 'knex': knexProxy }); My service includes knex. var knex =

Knex:Error Pool2 - error: password authentication failed for user

旧时模样 提交于 2020-05-27 07:23:30
问题 I am having trouble with my migration to Ubuntu Linux. I can use Postgres in the terminal. So I don't have a problem with the Postgres password. When I type: knex migrate:latest --env development I get: Using environment: development Knex:warning - Pool2 - Error: Pool was destroyed Knex:Error Pool2 - error: password authentication failed for user "user" I've read from other answers in related questions to go into the pg_hba.conf and set the method to trust. I've done this, but no change. my

Knex:Error Pool2 - error: password authentication failed for user

别等时光非礼了梦想. 提交于 2020-05-27 07:22:41
问题 I am having trouble with my migration to Ubuntu Linux. I can use Postgres in the terminal. So I don't have a problem with the Postgres password. When I type: knex migrate:latest --env development I get: Using environment: development Knex:warning - Pool2 - Error: Pool was destroyed Knex:Error Pool2 - error: password authentication failed for user "user" I've read from other answers in related questions to go into the pg_hba.conf and set the method to trust. I've done this, but no change. my

Knex:Error Pool2 - error: password authentication failed for user

倖福魔咒の 提交于 2020-05-27 07:22:21
问题 I am having trouble with my migration to Ubuntu Linux. I can use Postgres in the terminal. So I don't have a problem with the Postgres password. When I type: knex migrate:latest --env development I get: Using environment: development Knex:warning - Pool2 - Error: Pool was destroyed Knex:Error Pool2 - error: password authentication failed for user "user" I've read from other answers in related questions to go into the pg_hba.conf and set the method to trust. I've done this, but no change. my