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
FutureAPI, for reading its objects: what ReadCollection offers, each call aFuture. - AsyncReadTransaction
-
A read transaction of the
FutureAPI: 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
FutureAPI, for reading and writing its objects: what WriteCollection offers, each call aFuture. - AsyncWriteTransaction
-
A write transaction of the
FutureAPI. - BackupReport
- What a backup wrote.
- BoolField
-
A
boolfield. - BoolKind
-
trueorfalse. - BytesField
-
A
Uint8Listfield. - BytesKind
-
Any bytes, as a
Uint8List. - Change
-
A change of one field, for
update, which ValueField.set and thesetof 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
finalfields and a constructor that takes each by name;build_runnergenerates its schema constant, such asuserSchemaforUser, its query builder and acopyWith. -
CollectionSchema<
T, Q extends QueryBuilder< T> , K extends Object> -
A collection whose objects are of type
T, whose queriesQbuilds and whose primary key is of typeK: whatdarudb_generatormakes for a class annotated@Collection(), as a constant such asuserSchema. - 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 codedarudb_generatorwrites 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
doublefield. - 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
intfield. - IntKind
- A 64-bit integer.
- Kind
- The kind of a field: what values it holds.
-
Link<
T> -
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_generatorwrites 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, aStringor aUint8List. -
QueryBuilder<
T> -
The parts of a query: a filter, a sort, an offset and a limit. The code
darudb_generatorwrites 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
Stringfield. 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,CORRUPTEDand the rest.