I am working on simple query builder which will be used to generate orientdb queries. Orientjs has statement.js which can be use to generate the queries, but I am not sure if we could use to generate all types of queries.
For example:
select * from Employee where (FirstName like "A%" or FirstName like "B%") and (LastName like "G%" or LastName like "F%")
I tried different options to generate above query using orientjs statement, but not able to. Also, how we can generate query to do copy record using insert, select query?
Does statement.js support generating this type of queries?
For complex where clauses, you can just use a raw string:
db.select()
.from('Employee')
.where('(FirstName like "A%" or FirstName like "B%") and (LastName like "G%" or LastName like "F%")').all();
To create a copy of a vertex using select / insert, you can crate a transaction via the db.let function such as
return this.db
.let('original', (c) => {
c.select()
.from('Employee')
.where('(FirstName like "A%" or FirstName like "B%") and (LastName like "G%" or LastName like "F%")')
})
.let('copy', (c) => {c
.create('vertex','Employee')
.set('FirstName = $original[0].FirstName')
.set('LastName = $original[0].LastName')
})
.commit()
.return('$copy')
.one();