I'm trying to using sails-arangodb to connect sails to arangodb. I follow this guide: Arangodb use case guide to connect to arangodb. But i face error:
error: Error: The hook `orm` is taking too long to load. Make sure it
is triggering its `initialize()` callback, or else set `sails.conf
g.orm._hookTimeout to a higher value (currently 20000)
at Timeout.tooLong [as _onTimeout] (C:\Users\thanhtv\AppData\Roaming\npm\no
e_modules\sails\lib\app\private\loadHooks.js:85:21)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
here is my connections.js
module.exports.connections = {
localArangoDB: {
adapter: 'sails-arangodb',
host: '192.168.0.152',
port: 8529,
// user: 'root',
// password: 'root',
database: {
name: 'test',
graph: 'test'
}
// database: 'test',
//
// graph: 'test', // ArangoDB specific
// collection: 'test', // ArangoDB specific
},
};
and here is my models.js
module.exports.models = {
connection: 'localArangoDB',
migrate: 'alter'
};
I'm i missing something ?
Related
Iām trying to connect to RDS and seed data.
ormconfig.js
const entities = process.env.NODE_ENV === 'test' ? ['./src/**/**/*.ts'] : ['./dist/**/**/*.js'];
const logging = process.env.NODE_ENV !== 'test';
module.exports = {
type: 'postgres',
host: 'rds.ap-northeast-1.rds.amazonaws.com',
port: 5432,
username: 'postgres',
password: 'password',
database: 'db',
synchronize: true,
migrationsRun: false,
logging,
migrations: [`${__dirname}/dist/migration/*.js`],
entities,
};
// # sourceMappingURL=ormconfig.js.map
Error
ā Database connection failed! Check your typeORM config file.
RDS is running for sure and all the values of DB are from AWS Secrets Manager, so they are correct.
Why is this happening?
I am trying to establish a fixed connection pool using the typeorm for postgres in my rest service.
let option = {
name: 'default',
type: 'postgres',
host: 'host',
port: port,
username: 'username',
password: 'password',
database: 'database',
synchronize: true,
dropSchema: false,
logging: true,
ssl: {
ca: process.env.SSL_CERT,
},
entities: ['src/**/*.entity.ts'],
}
In app.ts
await createConnection(option).then(() => {
logger.debug('Database connection established');
}).catch((error: any) => {
logger.error('Database connection failed', error);
throw new Error(error);
});
When the app gets initialised the connectionpool gets established via ssl but it then closes, every time a query is executed the connection is created and then closed.
But without the ssl the connectionpool does not close until the .close method is called.
It would be helpful if someone could let me know on how to prevent the connectionpool from closing.
Or is there an option to set the time to live in ssl connection for postgres but I couldn't find reference for that in typeorm documentation.
I would like to use sails with sails-disk, migrate: drop so that whenever I run testcase I can have a new database with the following configuration on local.js. I am fine with sails lift. However, once I update migrate: drop or adapter to sails-disk or sails-memory. I am not able to sails lift from bootstrap and under server I can not even get configuration information. the sails lift just handling. without any detail message.
#config.js
module.exports = {
models: {
connection: 'testing',
migrate: 'drop',
},
connections: {
testing: {
adapter: 'sails-disk',
host: '127.0.0.1',
user: 'test',
password: 'test',
database: 'db',
},
},
};
#bootstrap.test.js
const TestConfig = require('./config/local');
before((done) => {
// Increase the Mocha timeout so that Sails has enough time to lift.
Sails.lift({
connections: TestConfig.connections,
models: TestConfig.models,
}, function(err) {
if (err) { return done(err); }
return done(err, server);
});
});
#error message
after adding more debug information before return I can not get config information
1) "before all" hook
0 passing (3s)
1 failing
1) "before all" hook:
Uncaught TypeError: Cannot read property 'config' of undefined
at async.series (test/bootstrap.test.js:29:26)
at node_modules/async/dist/async.js:3888:9
at node_modules/async/dist/async.js:473:16
at replenish (node_modules/async/dist/async.js:1006:25)
at node_modules/async/dist/async.js:1016:9
at eachOfLimit (node_modules/async/dist/async.js:1041:24)
at node_modules/async/dist/async.js:1046:16
at _parallel (node_modules/async/dist/async.js:3879:5)
at Object.series (node_modules/async/dist/async.js:4735:5)
at Sails.lift (test/bootstrap.test.js:19:11)
Since you're not providing any error message, I just can guessing that your config is wrong.
You have to name each connection and tell which one you want to use.
module.exports = {
models: {
migrate: 'drop',
connection : 'testing',
},
connections: {
testing : {
adapter: 'sails-disk',
host: '127.0.0.1',
user: 'user',
password: 'password',
database: 'db',
}
},
},
does anyone know how to connect to Google Cloud SQL from Sequelize?
sequelize = new Sequelize(process.env.TEST_DB || 'postgres', 'blah', null, {
dialect: 'postgres',
operatorsAliases: Sequelize.Op,
host: process.env.DB_HOST || 'localhost',
define: {
underscored: true
},
});
connected = true;
index.js
const sequelize = new Sequelize('{db_name}', '{db_user}', '{db_password}', {
dialect: 'mysql',
host: '/cloudsql/{instance}',
timestamps: false,
dialectOptions: {
socketPath: '/cloudsql/{instance}'
},
});
add this in serverless.yml
beta_settings:
cloud_sql_instances: {xxxxxxx-xxxxxx:us-central1:xxxxxxxxxxx}
You can connect from Sequelize like from any other client tool or ORM. Getting the access correctly depends on where you are running your code. If you code runs outside GCP, you can follow the external app instructions on this page:
https://cloud.google.com/sql/docs/postgres/connect-external-app.
If you are using proxy in your local computer, you set process.env.DB_HOST to 127.0.0.1. You can find troubleshooting tips at https://cloud.google.com/sql/docs/postgres/sql-proxy#troubleshooting.
I upgrade sails to 1.0, I resolved all the other errors but not able to resolved database connection issue,
It will be really helpful if anyone can reply on this.
module.exports.datastores = {
localDiskDb: {
adapter: 'sails-disk'
},
postgreSql: {
adapter: 'sails-postgresql',
// url: 'postgresql://admin:root#localhost:5432/testdb',
// ssl: true,
host: 'localhost',
user: 'admin',
password: 'root',
database: 'testdb'
},
};
Important Error Logs
I was using password which contains %
after changing the password sails successfully connected to postgresql.
It mostly looks like bug with Sails v1 or Sails-pgsql adapter.