How to use LiveQuery features in OrientJS? - orientdb

Exception in thread "Thread-9" java.lang.NullPointerException:
at com.orientechnologies.orient.server.network.protocol.binary.OLiveCommandResultListener.onLiveResult(OLiveCommandResultListener.java:110)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLLiveSelect$2.call(OCommandExecutorSQLLiveSelect.java:123)

server.use function add parameter useToken:true ,like this:
db = server.use({
name: 'test',
username: 'root',
password: '123456',
useToken :true
});

Related

Can't solve an error "āœ– Database connection failed! Check your typeORM config file. "

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?

sails cannot lift when changing adapter to sails-disk or sails-memory

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',
}
},
},

Create a model for OrientDB database in node.js

Iam building a node js application and OrientDB as the database. Is there someway to create a model for my vertices in node like we do if were using MongoDB?
For instance, I have a class called Account with propertise name, password and email.
Is it possible to create a model for this in node when using OrientDB and OrientJS as the language driver?
Appreciate any help.
I don't know if I understood it correctly, but this is how to create the class you described:
var OrientDB = require('orientjs');
var server = OrientDB({
host: 'localhost',
port: 2424,
username: '<username>',
password: '<password>'
})
var db = server.use({
name: 'mydb',
username: '<username>',
password: '<password>'
})
db.class.get('Account')
.then(function (MyClass) {
MyClass.property.create([{
name: 'name',
type: 'String'
},{
name: 'password',
type: 'String'
},{
name: 'email',
type: 'String'
}])
.then(function () {
console.log('Properties created')
});
})
server.close();
Hope it helps
Regards

how to connect arangodb with sails

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 ?

Sails.js controller not inserting into Mongo database

I've been all over SO and Sailsjs.org trying to figure out what's going wrong, and to no avail. Just trying to learn the basics of SailsJS. I have a UserController, whose create() method gets called when a POST request is sent to /user.
create: function (req, res) {
var params = req.params.all();
User.create({
name: params.FirstName + ' ' + params.LastName,
email: params.Email,
password: params.Password,
jobTitle: params.JobTitle
}).exec(function createCB(err,created)
{
created.save(function(err)
{
// No error . . . still nothing in db
});
return res.json({name: created.name, jobTitle: created.jobTitle, email: created.email, password: created.password});
});
}
No errors here. All the request params are coming in fine and going back to the client without trouble. But nothing is actually being written to the database.
In development.js:
connections: {
mongo: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
// user: 'username',
// password: 'password',
database: 'sails_test'
}
},
models: {
connection: 'mongo'
}
I've tried this with the above both there in development.js, as well as separately in connections.js and models.js, respectively. No difference.
In User.js:
attributes: {
FirstName : { type: 'string' },
LastName : { type: 'string' },
Email : { type: 'string' },
Password : { type: 'string' },
JobTitle : { type: 'string' }
}
My front end request:
$.ajax({
method: 'post',
url: '/user',
data: {
FirstName: 'Yo',
LastName: 'Momma',
Email: 'yourmom#yourdadshouse.com',
Password: 'YouWish123',
JobTitle: 'Home Maker Extraordinaire'
},
success: function (sailsResponse)
{
$('#result').html(sailsResponse).fadeIn();
},
error: function()
{
console.log('error');
}
});
Again, none of this is producing an explicit error. There is just nothing being inserted into the database. Or if there is, I don't know how to find it. I've confirmed the existence of this db in the mongo shell, thusly:
show dbs
My db, sails_test shows up in the list. And I've confirmed that there isn't anything in it like so:
db.sails_test.find()
I would very much appreciate some guidance here :)
Update:
Turns out the data is being written just fine. I'm just unable to query the database from the command line. I confirmed this by first creating a sample user, and then using Waterline's findOne() method:
User.findOne({FirstName: params.FirstName}).exec(function (err, user) {
if (err) {
res.send(400);
} else if (user) {
return res.json({firstName: user.FirstName, lastName: user.LastName, jobTitle: user.JobTitle, email: user.Email, password: user.Password});
} else {
return res.send('no users match those criteria');
}
});
The above works as expected. So my problem now is simply that I cannot interact with the database from the command line. db.<collectionName>.find({}) produces nothing.
This was simply a failure to understand the MongoDb docs. I read db.collection.find({}) as DatabaseName.CollectionName.find({}), when you literally need to use db. So if my database is Test, and my collection is Users, the query is use Test, and then db.Users.find({}).
Also of note, 3T Mongo Chef is a pretty rockin' GUI (graphical user interface) for nosql databases, and it's free for non-commercial use.