0 purchases
zddb
zddb 是一个简单易用的基于本地文档进行存储的数据库,使用纯 dart 开发,一个文件即为一张表,支持数据插入、修改、删除、查询。
Features #
纯 dart 开发,无任何外部依赖;
支持 int、double、boolean、words(64 byte)、string(1024 byte)、text(10240 byte) 数据类型;
支持条件查询,回调函数查询,分页查询等;
查询结果可直接读取为相应数据类型的字段;
Getting started #
dart pub add zddb
copied to clipboard
Usage #
import 'package:zddb/zddb.dart';
void main() async {
await create();
await queryByCondition();
await queryByHandle();
}
Future create() async {
final fields = [Field("name", FieldType.string), Field("age", FieldType.int)];
final db = DataBase.create("./test.db", fields: fields);
await db.insert(["Tom", 16]);
await db.insert(["Jerry", 20]);
await db.insert(["GG Bone", 24]);
await db.insert(["Loopy", 12]);
}
Future queryByCondition() async {
final db = DataBase.open("./test.db");
final condition = Condition(fieldName: "age", logic: Logic.gt, value: 16, reverse: true)
.add(Condition(fieldName: "name", logic: Logic.eq, value: "Jerry"), Typeid.or);
final rows = await db.query(condition: condition, offset: 0, limit: 2);
for (var row in rows) {
print("Name: ${row.getFieldAsString("name")}, Age: ${row.getFieldAsInt("age")}");
}
}
Future queryByHandle() async {
final db = DataBase.open("./test.db");
final rows = await db.query(handle: (row) => row.getFieldAsInt("age") == 20);
for (var row in rows) {
print("Name: ${row.getFieldAsString("name")}, Age: ${row.getFieldAsInt("age")}");
}
}
copied to clipboard
Additional information #
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.