search | |||||
---|---|---|---|---|---|
|
Insertion queries in OrientJS are those that add records of a given class into the database. The insertion query method is comparable to the INSERT
commands on the OrientDB Console.
In OrientJS, inserting data into the database uses the insert()
method. For instance, say that you want to add batting averages, runs and runs batted in for Ty Cobb.
db.insert().into('Player')
.set({
ba: 0.367,
r: 2246,
rbi: 1938
}).where('name = "Ty Cobb"').one().then(function(player){
console.log(player)
});
with set
db.insert().into('Player')
.set({
uuid : db.rawExpression("format('%s',uuid())"),
ba: 0.367,
r: 2246,
rbi: 1938
}).where('name = "Ty Cobb"').one().then(function(player){
console.log(player)
});
Generated query
INSERT INTO Player SET uuid = format('%s',uuid()), ba = 0.367, r = 2246, rbi = 1938