SQL to SequoiaDB 映射表

    Create 和 Alter

    SQL 语句API 语句
    create table student ( id not null, stu_id varchar(50), age number primary key(id) )创建时,集合无需描述结构。在插入文档记录时直接指定字段即可。特别地,集合的主键 _id 字段未指定时会自动添加。db.collectionspace.createCL( "student" )
    alter table student add name varchar(50)集合不描述或强制执行文档的结构,即在集合上没有结构的改动操作,但是 update() 方法可以使用 $set 向文档记录添加不存在的字段。db.collectionspace.student.update( { $set: { name: "unknown" } }, {} )
    alter table student drop column name集合不描述或强制执行文档的结构,即在集合上没有结构的改动操作,但是 update() 方法可以使用 $unset 向文档记录删除存在的字段。db.collectionspace.student.update( { $unset: { name: "" } }, {} )
    create index index_stu_id on student ( stu_id )db.collectionspace.student.createIndex( "index_stu_id", { stu_id: -1 } )
    drop table studentdb.collectionspace.dropCL( "student" )

    Select

    SQL 语句API 语句
    select from studentdb.collectionspace.student.find()
    select stu_id, age from studentdb.collectionspace.student.find( {},{ stu_id: "01", age: 20 } )
    select from student where age > 25db.collectionspace.student.find( { age: { $gt: 25 } } )
    select age from student where age = 25 and stu_id= "01"db.collectionspace.student.find( { age: 25, stu_id: "01" }, { age: 25 } )
    select count( * ) from studentdb.collectionspace.student.count()
    select count( stu_id ) from studentdb.collectionspace.student.count( { stu_id: { $exists: 1 } } )

    Delete

    SQL 语句API 语句
    delete from student where age = 20db.collectionspace.student.remove( { age: 20 } )
    delete from studentdb.collectionspace.student.remove()