darudb library

DaruDB, an embedded database that keeps an application's data in one local file.

Declare a class with @Collection(), run build_runner to generate its schema constant, and open a database with a Schema of them:

import 'package:darudb/darudb.dart';

part 'user.g.dart';

@Collection('users')
class User {
  const User({this.id, required this.name, this.age = 0});

  final int? id;
  final String name;
  @Index()
  final int age;
}

void main() {
  final db = Database.open('app.darudb', schema: Schema(1, [userSchema]));

  db.write((txn) => txn.collection(userSchema).insert(const User(name: 'Ada')));

  final adults = db.read(
    (txn) => txn.collection(userSchema).find((q) => q.where(q.age.atLeast(18))),
  );

  db.close();
}

Classes

AsyncReadCollection<T, Q extends QueryBuilder<T>, K extends Object>
A collection of a transaction of the Future API, for reading its objects: what ReadCollection offers, each call a Future.
AsyncReadTransaction
A read transaction of the Future API: one commit, as it was when the transaction began.
AsyncWriteCollection<T, Q extends QueryBuilder<T>, K extends Object>
A collection of a write transaction of the Future API, for reading and writing its objects: what WriteCollection offers, each call a Future.
AsyncWriteTransaction
A write transaction of the Future API.
BackupReport
What a backup wrote.
BoolField
A bool field.
BoolKind
true or false.
BytesField
A Uint8List field.
BytesKind
Any bytes, as a Uint8List.
Change
A change of one field, for update, which ValueField.set and the set of other fields make.
CheckProblem
A problem the integrity check found.
CheckReport
What the integrity check found: the commit it checked, how much it read, and every problem.
Collection
Makes the class the objects of a collection, named name, or after the class without one. The class has final fields and a constructor that takes each by name; build_runner generates its schema constant, such as userSchema for User, its query builder and a copyWith.
CollectionSchema<T, Q extends QueryBuilder<T>, K extends Object>
A collection whose objects are of type T, whose queries Q builds and whose primary key is of type K: what darudb_generator makes for a class annotated @Collection(), as a constant such as userSchema.
CompactReport
What compaction did.
Condition
A condition of a query's filter. Combine conditions with & (both hold), | (either holds) and ~ (it does not hold).
Database
An open database. There is no constructor: use Database.open.
Embedded
Makes the class an embedded object, which a field of an object holds.
EmbeddedField<E>
A field that holds an embedded object of type E. The code darudb_generator writes adds the embedded object's fields.
EmbeddedSchema<E>
The fields of an embedded object of type E, and how one is written and read.
Field
A field of a collection or an embedded object, as a query names it.
FieldSink
Writes the fields of one object, a field at a time, as the generated code tells it each field's value.
FieldSource
Gives the fields of one record, a field at a time, to the generated code that reads them into an object: the value the record holds, or the field's default or null when the record leaves it out, as a record written before the field existed does. Every field of the type comes once.
FieldSpec
A field as a schema declares it.
FloatField
A double field.
FloatKind
A 64-bit floating-point number.
Index
Keeps an index on the field, so that queries on it read only the objects they find.
IntField
An int field.
IntKind
A 64-bit integer.
Kind
The kind of a field: what values it holds.
A link to an object of collection T: the object's primary key.
LinkField
A link field: the key of the object linked to, compared as such. The code darudb_generator writes adds the linked collection's fields, which a condition reads through the link.
LinkKind
A link to an object of the collection collection: its primary key.
ListField<E extends Object>
A list field. A condition on a list holds when it holds for any element.
ListKind
A list of values of a scalar kind or of links.
Migration
A migration step from the version before version to version: the renames and deletions the engine cannot work out alone, and a function that moves data.
MigrationContext
What a migration function gets: the collections of the new schema, and the objects as the schema before the migration reads them.
Name
Names the field name in the collection, rather than as the Dart field is named.
ObjectKind
An embedded object, whose fields embedded declares.
OrderedField<V extends Object>
A field whose values have an order: comparisons and ranges.
PasswordHashing
What hashing a password costs: Argon2id memory in KiB, iterations and lanes. The default is 19 MiB, 2 iterations and 1 lane.
Prepared<T>
A query in the query language, parsed once, which each run gives values for its parameters.
PrimaryKey
Makes the field the collection's primary key: an int, a String or a Uint8List.
QueryBuilder<T>
The parts of a query: a filter, a sort, an offset and a limit. The code darudb_generator writes subclasses it with a getter for each field.
ReadCollection<T, Q extends QueryBuilder<T>, K extends Object>
A collection of a transaction, for reading its objects.
ReadTransaction
A read transaction: one commit, as it was when the transaction began.
SalvageReport
What salvage rescued.
Schema
A schema: a version, from 1 up, and its collections.
StringField
A String field. Strings compare by their UTF-8 bytes.
StringKind
UTF-8 text.
StringListField
A list of strings, whose elements can also be tested for how they start and end.
Unique
Keeps an index on the field that also refuses two objects with the same value. Any number of objects may hold null.
ValueField<V extends Object>
A field whose values are of type V, compared and set as such.
WriteCollection<T, Q extends QueryBuilder<T>, K extends Object>
A collection of a write transaction, for reading and writing its objects.
WriteTransaction
A write transaction: what a read transaction offers, with this transaction's changes, and the calls that change objects.

Enums

Durability
When a commit is durable.

Properties

engineVersion → String
The version of the DaruDB engine inside this package.
no setter
formatVersion → int
The file format version this build of the engine reads and writes.
no setter

Exceptions / Errors

DaruException
A failure of the database, with the engine's error code, the same string in every language DaruDB ships to: BUSY, DUPLICATE_KEY, INVALID_QUERY, CORRUPTED and the rest.