Cindel uses Dart annotations to mark model classes and fields for code generation. TheDocumentation 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.
cindel_generator reads these annotations at build time and produces typed collection getters, serializers, query helpers, and schema metadata. All annotations live in package:cindel_annotations; when you depend on package:cindel, they are re-exported and available through a single import.
@Collection / @collection
Marks a Dart class as a root persisted collection. Every class that should have its own collection in the database must be annotated with@Collection or the shorthand @collection.
Class: Collection
The stored collection name. When omitted, the generator derives the name from the Dart class name by lowercasing the first letter (e.g.
User → "user").Collection-level composite indexes. Use this for indexes that span more than one field. Single-field indexes are declared directly on the field with
@Index.@collection — equivalent to @Collection() with no name override and no composite indexes.
When to use
Use@Collection on every root model class. Prefer the named constructor when you need a specific storage name or composite indexes; use the @collection shorthand for simple classes where the generated default name is fine.
@Index / @index
Marks a single field as indexed. The generator creates a native index for the field and adds typedwhere() helpers that use it.
Class: Index
When
true, the index enforces that no two documents have the same value for this field.When
true and unique is also true, a write that conflicts with an existing document replaces the conflicting document instead of throwing. The generator produces a putByFieldName helper on the collection.Controls whether string comparisons are case-sensitive. Only applies to
String fields.The storage strategy for this index. See CindelIndexType below.
@index — equivalent to @Index() with all defaults.
When to use
Add@Index to any field you want to query through generated where() helpers or that would benefit from a backend index. For unique natural keys (e.g. email, sku), set unique: true. Combine with replace: true to enable natural-key upserts.
CindelIndexType
Controls how the native backend stores an index entry.| Case | Description |
|---|---|
value | Stores the original sortable value. Supports equality and range helpers (e.g. greaterThan, between). Default. |
hash | Stores a compact stable hash. Supports equality helpers only; does not support range queries. |
words | Splits a string into word tokens. Supports exact token lookup and token-prefix lookup. |
multiEntry | Adds one index entry per item in a primitive list. Supports list-membership queries. |
@Embedded / @embedded
Marks a Dart class as an embedded value object. Embedded objects are stored inside the parent collection document rather than in their own collection. They do not have anId field and cannot be queried independently.
Class: Embedded
This annotation takes no parameters.
Shorthand constant: @embedded — equivalent to @Embedded().
When to use
Use@embedded for value types that only make sense as part of a parent document — addresses, metadata blocks, nested lists of structured values, etc. Embedded objects can be nested, and the generator produces typed filter helpers that descend into them.
@Backlink
Declares a read-only inverse link. When a collection holds aCindelLink<T> or CindelLinks<T> forward link, the target class can expose the inverse through a CindelLinks field annotated with @Backlink.
Class: Backlink
The Dart field name of the forward link on the linked collection that this backlink mirrors.
When to use
Use@Backlink when you want to navigate a relation in reverse without duplicating any storage. The backlink is populated by loading the forward relation — it is read-only and cannot be saved directly.
@Name
Overrides the stored name for a collection, field, or embedded field. The generator uses the provided string everywhere the name appears in schemas, indexes, and native queries. Class:Name
The storage name to use instead of the Dart name.
When to use
Use@Name when the Dart name and the desired database name differ — for example, when migrating a renamed field while preserving backward compatibility with existing stored documents, or when following a naming convention that differs from Dart style.
@Enumerated
Configures how an enum field is persisted. Without this annotation, the generator falls back to the default persistence strategy for the detected enum type. Class:Enumerated
The persistence strategy. See CindelEnumType below.
The name of the enum instance field whose value should be stored when
type is CindelEnumType.value.When to use
Use@Enumerated whenever the default persistence strategy is not appropriate. Prefer CindelEnumType.name for human-readable storage, CindelEnumType.ordinal when compact integer storage is important, and CindelEnumType.value when the enum carries a stable string or integer code field that should survive reordering.
CindelEnumType
Controls how an enum value is written to storage.| Case | Stored as | Notes |
|---|---|---|
name | The enum case name string (e.g. "pro") | Human-readable; breaks if cases are renamed. |
ordinal | The zero-based case index integer | Compact; breaks if case order changes. |
value | The value of a named enum instance field | Stable across renames and reorders when the field value is kept constant. Requires valueField on @Enumerated. |
@Ignore / @ignore
Excludes a field from Cindel persistence. The generator skips the annotated field entirely — it is not stored, not indexed, and not part of any schema. Class:Ignore
This annotation takes no parameters.
Shorthand constant: @ignore — equivalent to @Ignore().
When to use
Use@ignore for computed properties, UI state, or any runtime-only field that should not be written to the database.
CompositeIndex
Declares a multi-field index at the collection level. Pass one or moreCompositeIndex instances in the indexes parameter of @Collection.
Class: CompositeIndex
The field names included in the composite key, in index order. Field names must match the Dart field names (or the
@Name override if one is present).Whether the combined composite value must be unique across documents.
Whether a write that conflicts with this unique composite index replaces the conflicting document instead of throwing.
Whether string comparisons within the composite key are case-sensitive.
When to use
UseCompositeIndex when a query filters or sorts on a combination of fields together and a single-field index would not be selective enough, or when you need a multi-field uniqueness constraint.
Id and autoIncrement
Id is a Dart typedef for int. Declare one Id field per collection class — the generator treats it as the document identifier.
autoIncrement is a sentinel const Id equal to -1. When a document’s id field holds autoIncrement at write time, Cindel allocates the next available id and assigns it back to the object.
Usage
dbId to any positive integer before calling put. Cindel will use that value directly rather than allocating a new one.