Documentation Index
Fetch the complete documentation index at: https://mintlify.com/mainser/cindel/llms.txt
Use this file to discover all available pages before exploring further.
CindelDatabase is the runtime handle that sits between your application code and the native storage engine. It is returned by Cindel.open and Cindel.openInMemory and provides access to typed collections via generated extension getters, raw transaction control via readTxn and writeTxn, and lower-level maintenance operations such as documentIds and documentIdsPage. Every interaction with the database flows through this object until close is called.
Properties
directory
Cindel.open. In-memory databases report the internal sentinel value ':memory:' rather than a real filesystem path.
The directory where database files are stored on disk, or
':memory:' for
databases opened with Cindel.openInMemory.backend
backend argument passed to Cindel.open or Cindel.openInMemory and does not change for the lifetime of the handle.
Either
CindelStorageBackend.mdbx or CindelStorageBackend.sqlite.isInWriteTransaction
true while this handle is executing the callback passed to writeTxn. This is false outside a write transaction and also false inside a readTxn callback.
true if a write transaction is currently active on this handle; false
otherwise.Lifecycle
close
Closes the database and releases all native resources held by this handle. Any active transaction is rolled back before the underlying engine connection is released. Registered watchers are cancelled. Calling close more than once is safe — subsequent calls are no-ops.
addTearDown:
Resolves when the native handle has been closed and all internal resources
have been freed.
Transactions
readTxn
Runs action inside a native read transaction, providing a consistent snapshot of the database for the duration of the call. All reads performed by this handle inside action observe the same committed state, even if other isolates or processes write to the database concurrently.
Attempting to call any write operation — such as put, delete, or writeTxn — inside a readTxn callback throws CindelTransactionError.
An asynchronous callback that executes inside the read transaction. The
transaction is held open for the entire duration of the
Future returned by
this callback. The callback must not start a nested transaction.Resolves to the value returned by
action after the read transaction commits.| Error | Condition |
|---|---|
CindelTransactionError | A write operation was attempted inside the read transaction, or a nested transaction was started. |
writeTxn
Runs action inside a native write transaction. All writes performed by this handle inside action are committed atomically when action completes successfully. If action throws, the transaction is rolled back and none of the pending writes are persisted. Watchers are not notified on rollback.
An asynchronous callback that executes inside the write transaction. Writes
from all typed collection methods called through this handle inside
action
participate in the same transaction. The callback must not start a nested
transaction.Resolves to the value returned by
action after the write transaction
commits. Registered watchers for affected collections are notified after the
commit completes.| Error | Condition |
|---|---|
CindelTransactionError | A nested transaction was started inside the callback. |
Collection Access
typedCollection
Returns a CindelTypedCollection<T> for the given schema. This is the low-level accessor that generated extension getters call internally. In most application code you will use the generated getter — for example db.users — instead of calling typedCollection directly.
The generated schema constant for the collection, for example
UserSchema.
The schema must have been passed to Cindel.open via the schemas parameter.A typed collection accessor for the collection described by
schema. The
accessor exposes get, put, delete, filter, where, watcher helpers,
and other generated operations.Maintenance
documentIds
Returns the complete list of document ids stored in collection, ordered ascending by id. The result is produced in a single native call and includes every id currently persisted in the collection.
For very large collections, prefer documentIdsPage to avoid materializing the full id list at once.
The collection name as declared in the
@Collection annotation or the name
parameter of CindelCollectionSchema. Must match a collection registered
with this database.A list of all document ids in the collection, sorted in ascending order.
Returns an empty list when the collection is empty.
documentIdsPage
Returns up to limit document ids from collection in ascending order, starting after afterId. This is the recommended approach for backup, export, and maintenance tooling that needs to scan large collections without loading the entire id set into memory at once.
documentIds when the total count is small enough to hold in memory:
The collection name. Must match a collection registered with this database.
When provided, only ids strictly greater than
afterId are returned. Omit
this parameter (or pass null) to start from the beginning of the
collection. On subsequent pages, pass the last id from the previous page.The maximum number of ids to return. Must be a positive integer. Defaults to
1000. The actual page size may be smaller when fewer ids remain after
afterId.Up to
limit document ids from collection, all strictly greater than
afterId, sorted in ascending order. Returns an empty list when the page
is exhausted or the collection is empty.Error Types
The methods onCindelDatabase throw typed errors from package:cindel/cindel.dart:
| Error | When thrown |
|---|---|
CindelDatabaseClosedError | A method is called after close() has been called. |
CindelTransactionError | A write is attempted inside readTxn, or a nested transaction is started. |
CindelOpenError | The native engine could not open the database (thrown by Cindel.open). |
CindelNativeError | The native engine returned an unexpected error from a storage operation. |
CindelSchemaError | A collection or field referenced in an operation has no registered schema. |
CindelQueryError | A query references a field that is not indexed, or an unsupported query shape is used. |
CindelUniqueIndexError | A put would violate a unique index constraint — a different document already holds the same value for a unique: true index field. |