文档

关于 SequoiaDB

快速入门

安装

基本操作

数据模型

SQL引擎

FileSystem引擎

S3引擎

系统架构

数据库管理

连接器

驱动

参考手册

故障排除

SAC 管控中心

Web服务

版本信息

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 ) ;
回到顶部