Somehow, my sails.js 1.x environment has gotten mangled to the point that I'm no longer able to do native queries to my PostgreSQL database. I'm sure the issue is the version of some package or another, because I did some experimentation with NodeJS 9 over the weekend, but this code was working on Friday and I can't seen to find the issue. Any suggestions?
sails> sails.getDatastore().sendNativeQuery('SELECT COUNT(*) FROM "user"').then(console.log);
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
sails> UsageError: Sorry, this function doesn't know how to handle {...} callbacks.
If provided, the 2nd argument should be a function like `function(err,result){...}`
| If you passed in {...} on purpose as a "switchback" (dictionary of callbacks),
| please be aware that, as of machine v15, you can no longer pass in a switchback
| as the 2nd argument. And you can't pass a switchback in to .exec() anymore either.
| Instead, you'll need to explicitly call .switch().
[?] See https://sailsjs.com/support for help.
at /Users/patrick/src/healthcelerate/hc-registry/node_modules/sails-hook-orm/lib/datastore-method-utils/private/do-with-connection.js:133:24
at _makeCallToDuringFn (/Users/patrick/src/healthcelerate/hc-registry/node_modules/sails-hook-orm/lib/datastore-method-utils/private/do-with-connection.js:101:28)
at /Users/patrick/src/healthcelerate/hc-registry/node_modules/sails-hook-orm/lib/datastore-method-utils/private/do-with-connection.js:103:7
at /Users/patrick/src/healthcelerate/hc-registry/node_modules/sails-hook-orm/lib/datastore-method-utils/private/do-with-connection.js:66:14
at /Users/patrick/src/healthcelerate/hc-registry/node_modules/machinepack-postgresql/node_modules/machine/lib/private/help-build-machine.js:966:24
at Function.handlerCbs.success (/Users/patrick/src/healthcelerate/hc-registry/node_modules/machinepack-postgresql/node_modules/machine/lib/private/help-build-machine.js:826:26)
at cb (/Users/patrick/src/healthcelerate/hc-registry/node_modules/machinepack-postgresql/machines/get-connection.js:87:20)
at BoundPool.<anonymous> (/Users/patrick/src/healthcelerate/hc-registry/node_modules/pg-pool/index.js:137:9)
at bound (domain.js:301:14)
at runBound (domain.js:314:12)
at /Users/patrick/src/healthcelerate/hc-registry/node_modules/generic-pool/lib/generic-pool.js:347:9
at BoundPool.<anonymous> (/Users/patrick/src/healthcelerate/hc-registry/node_modules/pg-pool/index.js:103:7)
at Connection.<anonymous> (/Users/patrick/src/healthcelerate/hc-registry/node_modules/pg/lib/client.js:158:7)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:121:20)
at Connection.emit (events.js:211:7)
at Socket.<anonymous> (/Users/patrick/src/healthcelerate/hc-registry/node_modules/pg/lib/connection.js:121:12)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:607:20)
sails>
Any tips or ideas would be much apprviated.
This turned out to be a bug in the version of Sails we were running. I upgraded sails to 1.0.2 and it resolved.
Related
I dont know why, but since I was cloning my working repository I am using on AWS to a local machine and try to run it, I am getting the following error:
"SCRAM-SERVER-FIRST-MESSAGE: client password must be a string"
Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string
at Object.continueSession (C:\Users\thehe\Documents\workspace\work\nft-trading-server\node_modules\pg\lib\sasl.js:24:11)
at Client._handleAuthSASLContinue (C:\Users\thehe\Documents\workspace\work\nft-trading-server\node_modules\pg\lib\client.js:257:10)
at Connection.emit (node:events:390:28)
at C:\Users\thehe\Documents\workspace\work\nft-trading-server\node_modules\pg\lib\connection.js:114:12
at Parser.parse (C:\Users\thehe\Documents\workspace\work\nft-trading-server\node_modules\pg-protocol\src\parser.ts:104:9)
at Socket.<anonymous> (C:\Users\thehe\Documents\workspace\work\nft-trading-server\node_modules\pg-protocol\src\index.ts:7:48)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:199:23)
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=admin
POSTGRES_PASSWORD=admin
POSTGRES_DB=nftapi01
PORT=5000
Does anyone know where that is coming from and how to fix this? I am not sure why I get this locally. I can connect to the pg database with the credentials of the .dev.env file but the Nest app wont start.
Are you importing the "dotenv" package? you need it for access to environment variables.
On your server.js file put: require('dotenv').config();
You said that you cloned your repository... do you have a package.json file in your project? (inside this file you declare what is your main file: "main": "server.js")
Of course, you need access to read your .env file, check them!
I am performing some automated tests on an API written in Loopback 2. These tests are basically an HTTP request on some methods of our API, which write and read data into a PostgreSQL database.
The following error is returned when one of the tests is run:
(node:2277) UnhandledPromiseRejectionWarning: error: duplicate key value violates unique constraint "role_pkey"
at Connection.parseE (/home/runner/work/arbobackend/arbobackend/node_modules/pg/lib/connection.js:602:11)
at Connection.parseMessage (/home/runner/work/arbobackend/arbobackend/node_modules/pg/lib/connection.js:399:19)
at Socket.<anonymous> (/home/runner/work/arbobackend/arbobackend/node_modules/pg/lib/connection.js:121:22)
at Socket.emit (events.js:198:13)
at Socket.EventEmitter.emit (domain.js:448:20)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as _originalOnread] (internal/stream_base_commons.js:94:17)
at TCP.onread (/home/runner/work/arbobackend/arbobackend/node_modules/async-listener/glue.js:188:31)
The problem is that when I run these tests on my machine, everything works correctly, the problem is when the tests are run in the Github Actions workflow.
The tests are run using Mocha and Chai.
I could not able to do MSSQL update from sails. I am facing below errors.
User.update({ id: 1 },
{ id: 1, name: 'test' }).exec(function afterwards (err, user) {
if (err) {
console.log(err);
} else {
console.log("Users updated:", users);
}
});
2018-03-21T08:21:52.868Z - error: error: Error (E_UNKNOWN) ::
Encountered an unexpected error RequestError: Incorrect syntax near
the keyword 'WHERE'. at Connection.
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\lib\tedious.js:658:17)
at emitOne (events.js:116:13) at Connection.emit (events.js:211:7)
at Parser.
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\connection.js:444:15)
at emitOne (events.js:116:13) at Parser.emit (events.js:211:7) at
Parser.nextToken
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\token\token-stream-parser.js:91:18)
at Parser.addBuffer
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\token\token-stream-parser.js:68:17)
at Connection.sendDataToTokenStreamParser
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\connection.js:891:35)
at Connection.data
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\connection.js:275:23)
at Connection.dispatchEvent
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\connection.js:752:59)
at MessageIO.
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\connection.js:680:22)
at emitOne (events.js:116:13) at MessageIO.emit (events.js:211:7)
at MessageIO.eventData
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\message-io.js:56:12)
at Socket.
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\message-io.js:3:59)
at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at
addChunk (_stream_readable.js:263:12) at readableAddChunk
(_stream_readable.js:250:11) at Socket.Readable.push
(_stream_readable.js:208:10) at TCP.onread (net.js:594:20)
Details: RequestError: Incorrect syntax near the keyword 'WHERE'.
Firstly try to use sails-mssql and if does not resolves your problem then go for below
Sails uses do not provide any specific method to debug query generate and executed with waterline Orm
Here are few method listed below to debug the problem more efficiently as the error stack say their is a problem in query near Where clause
2018-03-21T08:21:52.868Z - error: error: Error (E_UNKNOWN) :: Encountered an
unexpected error RequestError: Incorrect syntax near the keyword 'WHERE'. at
Connection.
1) Use these method to debug mssql management studio query log with
How to see query history in SQL Server Management Studio
2) Try to get to the driver of mssql > core file where it execute query and do console.log
hope it helps you
I am trying to run sequelize on Google Cloud functions, and trying to connect to a remote db hosted on compose.com, but I am getting this error
`
SequelizeHostNotFoundError: getaddrinfo ENOTFOUND gcp-us-east1-
cpu.2.dblayer.com gcp-us-east1-cpu.2.dblayer.com:16070
at connection.connect.err
(/user_code/node_modules/sequelize/lib/dialects/postgres/connection-
manager.js:95:24)
at Client.<anonymous>
(/user_code/node_modules/pg/lib/client.js:203:5)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at Socket.<anonymous>
(/user_code/node_modules/pg/lib/connection.js:86:10)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at connectErrorNT (net.js:1020:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
`
Any ideas what I might be doing wrong?
I found the problem.
I couldn't connect to an external API or address if I wasn't subscribed to a paid plan on Google Cloud Functions.
I have a multi-page mean.js app, that I need to host. I've tried the steps in this guide https://scotch.io/tutorials/deploying-a-mean-app-to-amazon-ec2-part-2 but when I try to run a local version of my app using a remote version of mongodb on an amazon EC2 instance, I run into the following error.
C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:246
throw message;
^
Error: Error setting TTL index on collection : sessions
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\connect-mongo\lib\connect-mongo.js:169:23
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1499:46
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1632:20
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\command_cursor.js:152:16
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1196:16
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1905:9
at Server.Base._callHandler (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:453:41)
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:488:18
at MongoReply.parseBody (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:68:5)
at null.<anonymous> (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:446:20)
at emit (events.js:107:17)
at null.<anonymous> (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:207:13)
at emit (events.js:110:17)
at Socket.<anonymous> (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection.js:440:22)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
In terms of my code, the only thing I've changed is replacing the line
module.exports = {
db: 'mongodb://localhost/borowr-dev',
with
module.exports = {
db: 'mongodb://MY_EC2_URL.com:27017/borowr-dev',
I previously tried updating my version of connect-mongo from 0.4.2 to 1.1.0, which caused other problems. Any help is appreciated, thanks.