- SQL to SequoiaDB shell to C
SQL to SequoiaDB shell to C
SequoiaDB 的查询用 json(bson)对象表示,下表以例子的形式显示了 SQL 语句,SequoiaDB shell 语句和 SequoiaDB C 驱动程序语法之间的对照。
SQL | SequoiaDB shell | C Driver |
---|---|---|
insert into bar( a, b ) values( 1, -1 ) | db.foo.bar.insert( { a: 1, b: -1 } ) | const char r = "{ a: 1, b: -1 }" ; jsonToBson ( &obj, r ); sdbInsert( collection, &obj ); |
select a,b from bar | db.foo.bar.find( null, { a: "", b: "" } ) | const char r = "{ a: "", b: "" }" ; jsonToBson ( & select, r ) ; sdbQuery ( collection, NULL, &select, NULL, NULL, 0, -1, cursor ) ; |
select from bar | db.foo.bar.find() | sdbQuery ( collection, NULL, NULL, NULL, NULL, 0, -1, cursor ) ; |
select from bar where age = 20 | db.foo.bar.find( { age: 20 } ) | const char r = "{ age: 20 }" ; jsonToBson ( &condition, r ); sdbQuery ( collection, & condition, NULL, NULL, NULL, 0, -1, cursor ); |
select from bar where age = 20 order by name | db.foo.bar.find( { age: 20 } ).sort( { name: 1 } ) | const char r1 = "{ age: 20 }" ; const char r2 = "{ name: 1 }" ; jsonToBson ( & condition, r1 ) ; jsonToBson ( &orderBy, r2 ) ; sdbQuery ( collection, & condition, NULL, & orderBy, NULL, 0, -1, cursor ) ; |
select from bar where age > 20 and age < 30 | db.foo.bar.find( { age: { $gt: 20, $lt: 30 } } ) | const char r = "{ age: { $gt: 20, $lt: 30 } }" ; jsonToBson ( &condition, r ); sdbQuery ( collection, & condition , NULL, NULL, NULL, 0, -1, cursor ) ; |
create index testIndex on bar( name ) | db.foo.bar.createIndex( "testIndex", { name: 1 }, false ) | const char r = "{ name: 1 }" ; jsonToBson ( &obj, r ); sdbCreateIndex ( collection, &obj, "testIndex", FALSE, FALSE ) |
select from bar limit 20 offset 10 | db.foo.bar.find().limit(20).skip( 10 ) | sdbQuery ( collection, NULL, NULL, NULL, NULL, 10, 20, cursor ) ; |
select count( ) from bar where age > 20 | db.foo.bar.find( { age: { $gt: 20 } } ).count() | const char r = "{ age: { $gt: 20 } }" ; jsonToBson ( &condition, r ); sdbGetCount ( collection, &condition, &count ) ; |
update bar set a=2 where b=-1 | db.foo.bar.update( { $set: { a: 2 } }, { b: -1 } ) | const char r1 = "{ $set: { a: 2 } }" ; const char r2 = "{ b: -1 }" ; jsonToBson ( &rule, r1 ) ; jsonToBson ( &condition, r2 ) ; sdbUpdate( collection, &rule, &condition, NULL ) ; |
delete from bar where a=1 | db.foo.bar.remove( { a: 1 } ) | const char *r = "{ a: 1 }" ; jsonToBson ( &condition, r ) ; sdbDelete ( collection, &condition, NULL ) ; |