flutter_instantdb_generator 0.2.0 copy "flutter_instantdb_generator: ^0.2.0" to clipboard
flutter_instantdb_generator: ^0.2.0 copied to clipboard

Build-time code generator for flutter_instantdb. Emits type-safe query tables, typed transactions, and relation accessors from @InstantModel-annotated models.

flutter_instantdb_generator #

Build-time code generator for flutter_instantdb. It turns plain annotated model classes into type-safe query tables, typed transactions, and relation accessors over the same InstantDB engine.

Install #

Add the runtime package as a dependency and the generator + build_runner as dev dependencies:

dependencies:
  flutter_instantdb: ^1.1.2

dev_dependencies:
  build_runner: ^2.4.13
  flutter_instantdb_generator: ^0.2.0

Usage #

Annotate a model with @InstantModel and declare it as a part:

import 'package:flutter_instantdb/flutter_instantdb.dart';

part 'todo.instant.dart';

@InstantModel('todos')
class Todo {
  final String id;
  final String title;
  @InstantField('done_at')
  final int? doneAt;
  const Todo({required this.id, required this.title, this.doneAt});
}

Run the generator:

dart run build_runner build --delete-conflicting-outputs

This emits todo.instant.dart with a TodoTable and typed extensions:

// Typed query
final todos = await TodoTable()
    .query()
    .where((t) => t.title.like('%urgent%'))
    .order((t) => t.title.asc())
    .getAll(db);

// Typed write
await db.transact(
  TodoTable().tx(db).createModel(Todo(id: db.id(), title: 'Ship it')),
);

Annotations #

  • @InstantModel('namespace') β€” marks a class as an InstantDB model.
  • @InstantField('attr') β€” overrides the stored attribute name for a field.
  • @InstantLink() β€” marks a relation field. Cardinality is inferred from the field type (List<T> β†’ to-many, T β†’ to-one); the target must itself be an @InstantModel. Emits a typed .include(...) accessor, a recursively-typed fromRow, and a RelationRef for typed linkRel/unlinkRel.

See the typed-layer docs for the full reference.

License #

MIT β€” see LICENSE.

0
likes
140
points
26
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

Build-time code generator for flutter_instantdb. Emits type-safe query tables, typed transactions, and relation accessors from @InstantModel-annotated models.

Repository (GitHub)
View/report issues

Topics

#instantdb #codegen #build-runner #source-gen #database

License

MIT (license)

Dependencies

analyzer, build, source_gen

More

Packages that depend on flutter_instantdb_generator