示例

每个 BOX 都是一个完全隔离的独立数据空间

using(var box = db.Cube())

{

//select, insert, update, delete ...

var result = box.Commit();

}

try(Box box = db.cube()){

...

CommitResult r = box.commit();

}

普通对象操作

box["Member"].Insert(new Member() {

ID=box.NewId(),

Name = "Andy",

Password = EncodePassowrd("123")

}

);

Member m = new Member();

m.ID = box.newId();

m.setName("Kevin");

box.d("Member").insert(m);

动态列的文档数据

game["GameType"] = "ACT";

box["Product"].Insert(game);

game.put("GameType", "ACT");

box.d("Product").insert(game);

键-值风格的查询

box["Table", 2L].Select();

//支持复合键

box["Table2", 99, "ABC"].Select();

box.d("Table", 3L).select(Member.class);

//支持复合键

box.d("Table2", 88, "ABC").select(Product.class);

SQL 风格数据查询

//from TABLE where A>? & B<=? order by C limit 0,10

box.Select("from Member where Name==?", "MyName");

//from [table] where [condition]

// order by [field1] desc,[field2] limit [0,10]

//[Condition:] == != < <= > >= & | ( )

//[IFunction:] =[F1,F2,F3]

box.select(Member.class, "from Member where Name==?", "MyName");

自定义查询函数

box.Select("from Member where [Tags]", new Query("Value"));

兼容 LINQ (.NET)

from o in box.Select("from Class")

where o.Text.Contains(text)

select o;

兼容 Stream (Java8)

StreamSupport.stream(db.select("from Table").spliterator(), true)

.collect(Collectors.groupingBy((l) -> l.get("GroupID"),

Collectors.summingLong((l) -> (Long) l.get("Value"))));

更新自增

作用域

触发条件

数据类型

数据来源

主键自增

主键

插入

数字

Table Max(ID)+1

更新自增

非主键

插入/更新

长整数

Database NewId(MaxPos,1)

查询追溯

线程

用法

数据锁

阻塞

读写同一数据行

查询追溯

不阻塞

读写不同的数据行

Snapshot-Serializable 两级事务

程序区域

隔离级别

应用程序

Snapshot

数据库

Serializable

数据类型支持

.NET

JAVA

bool

char

byte

sbyte

short

ushort

int

uint

long

ulong

float

double

decimal

DateTime

Guid

bool?

char?

byte?

sbyte?

short?

ushort?

int?

uint?

long?

ulong?

float?

double?

decimal?

DateTime?

Guid?

string

//non-indexable

MemoryStream

Dictionary

boolean

Boolean

byte

Byte

char

Character

short

Short

int

Integer

long

Long

float

Float

double

Double

UUID

Date

//dynamic length

BigDecimal

BigInteger

String

//Non-Indexable

byte[]

HashMap

Object[]

数据持久层

.NET

JAVA

class BoxFileStreamConfig

class BoxMemoryStreamConfig

class ReadonlyStreamConfig

class CacheStreamConfig

class BoxFileStreamConfig

class BoxMemoryStreamConfig

class ReadonlyStreamConfig

class CacheStreamConfig

数据库路径设置

C# & JAVA,  把数据库文件放到项目工作目录外会有更好性能

iBoxDB.LocalServer.DB.Root("/data/");

ASP.NET Cross Platform

iBoxDB.LocalServer.DB.Root(MapPath("~/App_Data/"));

Xamarin

iBoxDB.LocalServer.DB.Root(System.Environment.GetFolderPath(

System.Environment.SpecialFolder.Personal));

Unity3D

iBoxDB.LocalServer.DB.Root(Application.persistentDataPath);

Android

iBoxDB.LocalServer.DB.root(android.os.Environment.getDataDirectory()

.getAbsolutePath() + "/data/" + packageName + "/");

JSP WebApplication

@WebListener()

public class StartListener implements ServletContextListener {

@Override

public void contextInitialized(ServletContextEvent sce) {

String path = System.getProperty("user.home") + "/data/";

new File(path).mkdirs();

iBoxDB.LocalServer.DB.root(path);

}

}

查询方式

//查询

box.Select("from Member");

//查询,提前加载内存, 以 '*' 开始

box.Select("*from Member");

//查询追溯, 以 '!' 开始

box.Select("!from Member")

支持索引提升查询速度

config.EnsureIndex("Member", "Field1","Field2")

config.ensureIndex(Member.class, "Member", isUnique,"Field1","Field2")

box.Select("from Member where Field1 == ? & Field2 == ?")

快速入门   C# and JAVA

using iBoxDB.LocalServer;

var db = new DB();

db.GetConfig().EnsureTable("Table", "ID");

AutoBox auto = db.Open();

auto.Insert("Table", new Record { ID = 1L, Name = "Andy" });

var o1 = auto.Get("Table", 1L);

o1.Name = "Kelly";

auto.Update("Table", o1);

auto.Delete("Table", 1L);

import iBoxDB.LocalServer.*;

DB db = new DB();

db.getConfig().ensureTable(Record.class, "Table", "ID");

AutoBox auto = db.open();

auto.insert("Table", new Record(1L, "Andy"));

Record o1 = auto.get(Record.class, "Table", 1L);

o1.Name = "Kelly";

auto.update("Table", o1);

auto.delete("Table", 1L);

安装使用

.NET: 在项目中引用 NETDB/iBoxDB.DLL

Java: 在项目中引用 JavaDB/iBoxDB.jar

与 MySQL 的性能参照

iBoxDB

Insert: 1,000,000 AVG: 47,016 objects/s

Update: 1,000,000 AVG: 25,558 objects/s

Delete: 1,000,000 AVG: 42,714 objects/s

MySQL

Insert: 1,000,000 AVG: 5,514 objects/s

Update: 1,000,000 AVG: 5,109 objects/s

Delete: 1,000,000 AVG: 6,044 objects/s

复合键支持

55bb1186b4d6c0997fa838c06031f7e4.png

config.ensureTable(Item.class, "Item", "UID", "Type")

数据库同步,主从与多主

65deb22c7ccf241b1ea963aa33e37247.png

7f3fa418a87bc67f55fadcdeefb5dbaa.png

Logo

openvela 操作系统专为 AIoT 领域量身定制,以轻量化、标准兼容、安全性和高度可扩展性为核心特点。openvela 以其卓越的技术优势,已成为众多物联网设备和 AI 硬件的技术首选,涵盖了智能手表、运动手环、智能音箱、耳机、智能家居设备以及机器人等多个领域。

更多推荐