Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you do an 'Insert if not exists' using orientjs?

Tags:

What is the idiomatic way for doing an 'insert if not exists'?

Can this be done without transactions?

like image 341
Bradley Serbu Avatar asked Aug 29 '16 19:08

Bradley Serbu


1 Answers

Try this:

with upsert creates a record if it doesn't exists, unless it updates

var OrientDB = require('orientjs');

 var server = OrientDB({

     host: 'localhost',
     port: 2424,
     username: 'root',
     password: 'root'

 });

 var db = server.use({

     name:  'GratefulDeadConcerts',
     username: 'root',
     password: 'root'

 })

 db.query('UPDATE V SET id = 23 UPSERT WHERE id = 23')
 .then(function (response) {
    console.log(response);
});

 server.close();

Hope it helps.

Regards

like image 155
Michela Bonizzi Avatar answered Sep 24 '22 16:09

Michela Bonizzi