I am trying to connect sails 1.0 to SQL Server, but I've been out of luck so far. There doesn't seem to be anything publicly available.
I did found someone on GitHub that did try to add support, although when i try to use their branch it didn't work out too well.
Got this error when I try to use the model.findOne() method.
name: 'RequestError',
message: 'Incorrect syntax near \'BY\'.',
code: 'EREQUEST',
number: 102,
lineNumber: 1,
state: 1,
class: 15,
serverName: 'sql1b',
procName: '',
precedingErrors: [] }
Was anyone else more lucky in getting sails 1.0 to work with a SQL Server database?
Yes, you can try sails-sqlserver-sailsv1. But don't follow the guide in the npm site, probably a copy/paste error on how to install the package. use:
npm install sails-sqlserver-sailsv1 --save
And in the datastore configuration on sails make sure to use the correct adapter name:
default: {
adapter: 'sails-sqlserver-sailsv1',
user: 'cnect',
password: 'pass',
host: 'abc123.database.windows.net' // azure database
database: 'mydb',
options: {
encrypt: true // use this for Azure databases
}
}
I hope it helps you.
You may want to change from waterline - default SailS ORM - to Sequelize + Tedious. Waterline is very dependent on the work of the opensource community, and thus SQL Server is not (and I don't think it will ever be) supported.
Related
Im on a mac(OS 10.14) using nodejs 14 and PostgresSQL 12.
I just installed Loopback4 and after following this tutorial Im not able to use any of the enpoints that use Models, ie that connect to Postgres, I constantly get a timeout.
It seems like its not even reaching the Postgres Server, but the error gives no information, just that the request times out.
There are no issues with the Postgres server since I can connect and request information with other nodejs applications to the same database.
I also tried to set this as the host host: '/var/run/postgresql/', same result.
I now tried the approach with a Docker container, setting the datasource files as follows:
import {inject, lifeCycleObserver, LifeCycleObserver} from '#loopback/core';
import {juggler} from '#loopback/repository';
const config = {
name: 'mydb',
connector: 'postgresql',
url: 'postgres://postgres:mysecretpassword#localhost:5434/test',
ssl: false,
};
// Observe application's life cycle to disconnect the datasource when
// application is stopped. This allows the application to be shut down
// gracefully. The `stop()` method is inherited from `juggler.DataSource`.
// Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html
#lifeCycleObserver('datasource')
export class PostgresSqlDataSource extends juggler.DataSource
implements LifeCycleObserver {
static dataSourceName = 'PostgresSQL';
static readonly defaultConfig = config;
constructor(
#inject('datasources.config.PostgresSQL', {optional: true})
dsConfig: object = config,
) {
super(dsConfig);
}
}
With that same url I can log on my command line from my mac.
Is there a way to add logging and print any connection error? Other ways to debug it?
[UPDATE]
As of today Loopback4 Postgres connector does not work properly with Nodejs 14.
When starting the application, instead of running
npm start, you can set the debug string by running:
DEBUG=loopback:connector:postgresql npm start
If you want it to be more generic, you can use:
DEBUG=loopback:* npm start
This is my first question in Stack Overflow so please excuse me when my information is lack.
Issue
I am struggling to connect PostgreSQL on CloudSQL from NestJS on Google App Engine.
When I try to use the application in local environment the program works but when it comes to production in Google App Engine then it does not work.
Since i struggled days, I decided to ask awesome community here.
My Environment
Node.js: v10.19.0
NestJS: 6.10.5
TypeORM
PostgreSQL: 11.5.1
My app.yaml
runtime: nodejs10
env: standard
default_expiration: "4d 5h"
env_variables:
DATABASE_HOST: < public IP for Cloud SQL instance >
DATABASE_USERNAME: username
DATABASE_PASSWORD: password
DATABASE_NAME: databasename
INSTANCE_CONNECTION_NAME: "PROJECT_ID:REGION:INSTANCE_ID:DATABASE_NAME"
handlers:
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
Error
[Nest] 18 - 02/27/2020, 8:25:46 AM [TypeOrmModule] Unable to connect to the database. Retrying (3)... +34816ms
2020-02-27 08:25:46 default[20200227t163916] Error: connect ETIMEDOUT 34.84.188.209:5432 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:
Others Operations
GAE Service Account
Also I added the Cloud SQL Client authority my GAE Service account (something like this service-PROJECT_ID#gae-api-prod.google.com.iam.gserviceaccount.com).
I also added package.json as written in below:
"engines": {
"node": "10.x.x"
},
In the typeorm options, I added extra socketpath.
extra: {
socketPath: `/cloudsql/<INSTANCE_CONNECTION_NAME>/`,
},
I do not understand if this option should be set or not (I have tried both).
socketPath: `/cloudsql/<INSTANCE_CONNECTION_NAME>/.s.PGSQL.5432
or
socketPath: `/cloudsql/<INSTANCE_CONNECTION_NAME>
According to the example provided in GitHub
https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/appengine/cloudsql_postgresql/app.flexible.yaml
The INSTANCE_CONNECTION_NAME environment variable does not include the DATABASE_NAME as a parameter.
e.g. my-awesome-project:us-central1:my-cloud-sql-instance
Maybe this could be causing that the name of the instance is not being resolved for the Proxy.
Recently, I took over a Sails.js application created for our company by a small team of web developers. They provided me with the source and a database dump. Now, my task is to get it up and running on Heroku. While everything is working okay when I run the app locally, with the remote connection there is an error on startup that says:
MongoError: not authorized on heroku_gbntc8sf to execute command { createIndexes: "agendaJobs", indexes: [ { key: { name: 1, priority: -1, lockedAt: 1, nextRunAt: 1, disabled: 1 }, name: "findAndLockNextJobIndex1" }, { key: { name: 1, lockedAt: 1, priority: -1, nextRunAt: 1, disabled: 1 }, name: "findAndLockNextJobIndex2" } ] }
at Function.MongoError.create ([ROOT_DIR]/node_modules/mongodb-core/lib/error.js:31:11)
at [ROOT_DIR]/node_modules/mongodb-core/lib/topologies/server.js:793:66
at Callbacks.emit ([ROOT_DIR]/node_modules/mongodb-core/lib/topologies/server.js:94:3)
at null.messageHandler ([ROOT_DIR]/node_modules/mongodb-core/lib/topologies/server.js:235:23)
at Socket.<anonymous> ([ROOT_DIR]/node_modules/mongodb-core/lib/connection/connection.js:259:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
Here's a quick checklist of what I've done already:
checked the build log on Heroku - no errors or warnings;
set up mLab Heroku add-on, exported the database, done some manual checks from the mLab dashboard - everything looks okay;
logged in to the database remotely from the mongo command and a mongo:// URL, ran a few simple queries, and obtained information on the database user privileges;
created an identical user (with the heroku_gbntc8sf username, same password, same role, etc.) in the local database.
Here's what the connection configuration looks like:
// config/connections.js
module.exports.connections = {
mongodb: {
adapter: 'sails-mongo',
user: 'heroku_gbntc8sf',
password: [HIDDEN],
host: 'ds159387.mlab.com',
port: 59387,
database: 'heroku_gbntc8sf'
},
// ...
}
// config/env/development.js
module.exports = {
models: {
connection: 'mongodb'
},
// ...
}
// config/env/production.js
module.exports = {
models: {
connection: 'mongodb'
},
// ...
}
At the moment I'm running the server locally, trying to connect to the remote database, to eliminate as many variables as possible. Like I mentioned above, when I set host to '127.0.0.1' and port to 27017, everything works okay. The heroku_gbntc8sf user has basic readWrite permissions in both databases (local and remote). In fact, those two databases are pretty much identical, as far as I know. And yet...
I've read a sizeable chunk of the Sails.js documentation, as well as, the documentation on the sails-mongo adapter. I've searched for similar questions, but I couldn't find anything relevant. I've tried many different things, including a couple of different ways to configure the database connection, but that error is always there.
The reason why I'm posting to StackOverflow is that I cannot rely on the support from the original authors of the app at the moment. Also, I'm new to Sails.js, so I might be doing something wrong without even knowing. I was hoping that I could get away with treating the app as a 'black box' (or like a generic Node application), since my job is only to start the app on Heroku.
I've successfully used mLab in a Sails project recently, but I've used the Mongo URL string format, for example...
mongodbServer: {
adapter: 'sails-mongo',
url : "mongodb://dandanknight:som3P455w0rd#ds044979.mlab.com:44979/databasename"
}
Not sure if it helps, but can't hurt to try! It's also the only way I've successfully got a replicaSet working in Sails incidentally.
It's confusing, but I read the sails-mongo docs as "URL is the way forward, and passing an object is legacy usage" (here)
I am right now attempting my first Heroku deployment of a SailsJS API. My app uses SailsJS v0.11 andsails-mongo 0.11.2.
I have updated config/connections.js to include the connection information to MongoDB database I have hosted for free at Mongolab.
mongodb: {
adapter: 'sails-mongo',
url: "mongodb://db-user:password123#ds047812.mongolab.com:47812/testing-db"
}
Also updated config/models.js to point to that adapter.
module.exports.models = {
connection: 'mongodb',
migrate: 'safe'
};
This is basically all I have changed from running the code locally, when I deploy to Heroku the app crashes and I get this error...
/home/zacharyhustles/smallChangeAPI/node_modules/connect-mongo/lib/connect-mongo.js:186
throw err;
^
at Socket.emit (events.js:107:17)
2015-07-08T19:37:00.778316+00:00 app[web.1]:
at Socket.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
Error: Error connecting to database: failed to connect to [localhost:27017]
How do I get rid of this, and make sure Sails does not try connecting to localhost db?
Ok, the problem was with storing sessions.
My solution was to setup a Redis database to store sessions.
In config/sessions.js make sure everything is commented out except for the method you want for session store.
Mine looked like this:
adapter: 'redis',
host: 'example.redistogo.com',
port: 1111,
db: '/redistogo',
pass: 'XXXXXYYYYYYXYXYXYYX',
This solved my posted problem, hope this helps another person out.
I had issues correctly configuring my couchbase adapter in sails-js. I am using the sails-cbes adapter. The documentation fails to mention the key to use. For any who might struggle as I did, below is my configuration file:
{
...
//couchbase
cb: {
adapter: 'sails-cbes',
host: 'localhost',
port: 8091,
user: 'user',
pass: 'password',
bucket: {
name: 'bucket',
pass: 'bucketPassword'
}
}
},
...
Assuming that by 'key' you refer to the 'password' fields:
The first password is the one you set up in the dialogue the first time you log in to https://localhost:8091.
The bucket is not being created automatically so you would have to do that manually in couchbase. Then you have the option to set a password for the bucket itself, but the default is just empty string. Elasticsearch indexing is automated as long as you declare the mapping in the model.
The configuration file should be in sails-project/config/connections.js and it should look something like this:
sailsCbes: {
adapter: 'sails-cbes',
cb: { ... },
es: { ... }
}
You can try it out by creating a model within sails that uses this connection.
As for the dependencies, you need to install couchbase and elasticsearch yourself, then from the sails-cbes folder do a sudo npm install and you should be good to go. For test dependencies, run npm install inside the test folder.
Hope this helps
I think you don't understand how sailsjs adapter works.
Please spend some time and read the documentation of sailsjs, specially the connections configuration (adapters)
http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html