SequoiaDB 巨杉数据库的查询用 json(bson)对象表示,下表以示例的形式展示 SQL 语句、SDB Shell 语句和 SequoiaDB C++ 驱动程序语法之间的对照。
SQL | SDB Shell | C++ Driver |
---|---|---|
insert into employee( a, b ) values( 1, -1 ) | db.sample.employee.insert( { a: 1, b: -1 } ) | sdbCollection collection ; BSONObj obj = BSON( "a" << 1 << "b" << -1 ) ; collection.insert( obj ) ; |
select a,b from employee | db.sample.employee.find( null, { a: "", b: "" } ) | sdbCollection collection ; sdbCursor cursor ; BSONObj selected ; BSONObj obj ; selected = BSON( "a"<<""<<"b"<<"" ) ; collection .query( cursor, obj, selected ) ; |
select * from employee | db.sample.employee.find() | sdbCollection collection ; sdbCursor cursor ; collection.query ( cursor ) ; |
select * from employee where age=20 | db.sample.employee.find( { age: 20 } ) | sdbCollection collection ; sdbCursor cursor ; BSONObj condition ; condition = BSON( "age" << 20 ) ; collection .query ( cursor, condition ) ; |
select * from employee where age=20 order by name | db.sample.employee.find( { age: 20 } ).sort( { name: 1 } ) | sdbCollection collection ; sdbCursor cursor ; BSONObj obj ; BSONObj condition ; BSONObj orderBy ; condition = BSON( "age"<<20 ) ; orderBy = BSON( "name"<<1 ) ; collection.query( cursor, condition, obj, orderBy, obj ) ; |
select * from employee where age > 20 and age < 30 | db.sample.employee.find( { age: { $gt: 20, $lt: 30 } } ) | sdbCollection collection ; sdbCursor cursor ; BSONObj condition ; condition = BSON( "age" << BSON( "$gt" << 20 << "$lt" << 30 ) ) ; collection.query( cursor, condition ) ; |
create index testIndex on employee( name ) | db.sample.employee.createIndex( "testIndex", { name: 1 }, false ) | sdbCollection collection ; BSONObj obj ; obj = BSON( "name"<<1 ) ; collection.createIndex ( obj, "testIndex", FALSE, FALSE ); |
select * from employee limit 20 offset 10 | db.sample.employee.find().limit( 20 ).skip( 10 ) | sdbCollection collection ; BSONObj obj ; sdbCursor cursor ; collection .query( cursor,obj, obj, obj, obj, 10, 20 ) ; |
select count(*) from employee where age > 20 | db.sample.employee.find( { age: { $gt: 20 } } ).count() | sdbCollection collection ; SINT64 count = 0 ; BSONObj condition ; condition = BSON( "age" << BSON( "$gt" << 20 ) ) ; collection.getCount( count, condition ) ; |
update employee set a=2 where b=-1 | db.sample.employee.update( { $set: { a: 2 } }, { b: -1 } ) | sdbCollection collection ; BSONObj condition = BSON( "b"<<-1 ) ; BSONObj rule = BSON( "$set" << BSON( "a" << 2 ) ); BSONObj obj ; collection.update ( rule, condition, obj ) ; |
delete from employee where a=1 | db.sample.employee.remove( { a: 1 } ) | sdbCollection collection ; BSONObj condition = BSON( "a"<<1 ) ; collection.del ( condition ) ; |