knex.js

How to use the Knex CLI

假装没事ソ 提交于 2020-01-03 08:48:25
问题 I have installed Knex in my Node project and all is wonderful and great... so far... Now I dig deeper into Knex and am confronted with migrations. All the docs I found talk about running commands like "knex migrate:latest", etc. What I get as a result when I try to run such commands from the (Windows) command line is an error telling me that 'knex' is an unknown command. I am not a npm and Nodes expert, just enough to get the basics running. When digging into the knex node package I find some

Unable to catch knex transaction rejection

允我心安 提交于 2020-01-03 07:05:09
问题 I'm using knex transaction with async/await syntax as suggested in this question: Get Knex.js transactions working with ES7 async/await My problem is, that when transaction fails and trx callback is invoked, knex logs Unhandled rejection error: relation "some_table" doesn't exist // Example error which I used for testing just under the same error logged by logger, so logs looks like that: // Removed error stacks... // Error logged by logger 2019-07-14T23:12:29.606Z [error]: error: insert into

Knexjs returning mysql timestamp, datetime columns as Javascript Date object

会有一股神秘感。 提交于 2020-01-02 05:44:35
问题 i am using knexjs i insert data in the format YYYY-MM-DD HH:mm:ss e.g 2017-07-14 15:00:00 and after saving when the data is fetched the datetime column values are returned as javasript Date object. i want to return those object in the format YYYY-MM-DD HH:mm:ss but it returning in the format YYYY-MM-DDTHH:mm:ss.000Z e.g 2017-06-23T06:44:44.000Z . i am returning them by iterating and converting them manually. i was wondering if there is another way to do it like in mysql driver or knexjs

Cleaning database after tests in node.js

一个人想着一个人 提交于 2020-01-01 09:32:07
问题 How I can clean database after each it ? In rails I use https://github.com/bmabey/database_cleaner, but I did't find something similar for node.js node.js (v0.10.26), PostgreSQL (9.3.3), mocha, restify and knex. 回答1: The easy way I have found to clean the database between test is to DROP SCHEMA public CASCADE; CREATE SCHEMA public AUTHORIZATION my_test_user; Once the public schema belongs to the test user, he is able to drop and re-create the schema when needed. Be aware that drop everything

Cloud SQL instance connection working locally, but not on App Engine

感情迁移 提交于 2019-12-30 10:32:45
问题 I am trying to host an API implemented as a Node.js app on Google Cloud App Engine. The database that the API utilizes is a PostgreSQL 9.6 database which is hosted with a Cloud SQL instance. The database is connected to the Node.js API through Knex . When hosted on App Engine, the API endpoints that do not require any contact with the database work fine. However, when the database needs to be contacted to complete the API call, the following error appears in the logs: Unhandled rejection

Cloud SQL instance connection working locally, but not on App Engine

前提是你 提交于 2019-12-30 10:32:40
问题 I am trying to host an API implemented as a Node.js app on Google Cloud App Engine. The database that the API utilizes is a PostgreSQL 9.6 database which is hosted with a Cloud SQL instance. The database is connected to the Node.js API through Knex . When hosted on App Engine, the API endpoints that do not require any contact with the database work fine. However, when the database needs to be contacted to complete the API call, the following error appears in the logs: Unhandled rejection

Cloud SQL instance connection working locally, but not on App Engine

对着背影说爱祢 提交于 2019-12-30 10:31:12
问题 I am trying to host an API implemented as a Node.js app on Google Cloud App Engine. The database that the API utilizes is a PostgreSQL 9.6 database which is hosted with a Cloud SQL instance. The database is connected to the Node.js API through Knex . When hosted on App Engine, the API endpoints that do not require any contact with the database work fine. However, when the database needs to be contacted to complete the API call, the following error appears in the logs: Unhandled rejection

How to connect to SQL Server with Windows authentication from Node.JS using knex module

北战南征 提交于 2019-12-25 17:16:15
问题 I am trying to connect SQL Server using knex with Windows Authentication from my node.js application. Config: { client: 'mssql', connection: { database: 'MyDBName', host: 'xx.xx.xx.xxx', server: 'MY-SERVER_NAME\\SQLEXPRESS', options: { encrypt: false, trustedConnection: true, }, }, } I didn't add username and password in the config as I have added trustedConnection: true for Windows Authentication . But I am getting the following error: Login failed for user ''. Even if I add add username and

how to set knex connection ssl options when using a connection string

邮差的信 提交于 2019-12-24 14:57:15
问题 How can I set my connection's ssl property to true when I'm using a connection string to initialize knex? Similarly how to set the debug to true? I would normally pass in a connection object but in this case I have to use a connection string from environment variables. var database = { client: 'pg', connection: connstr //normally I would pass in the object below //connection: { // "host": config.get('database_host'), // "user": config.get('database_user'), // "password": config.get('database

How to update a key of object with value in json column with knexjs?

做~自己de王妃 提交于 2019-12-24 07:56:34
问题 I'm trying to update a column in users table the column type is json . column name is test. and the column consists of an object default value for example is {a: "text", b: 0} how to update let's say the object key b without changing the whole column the code i'm using is knexDb('users').where({ email: email }) .update({ test: { b: 1 } }) second solution knexDb('users').where({ email: email }) .update({ test: knexDb.raw(`jsonb_set(??, '{b}', ?)`, ['test', 1]) }) first solution changes the