nitrite_generator 1.1.0 copy "nitrite_generator: ^1.1.0" to clipboard
nitrite_generator: ^1.1.0 copied to clipboard

Nitrite entity generator. Automatically generates Nitrite entities from Dart classes.

example/example.dart

import 'package:nitrite/nitrite.dart';

part 'example.no2.dart';

@Convertable(className: 'MyBookConverter')
@Entity(name: 'books', indices: [
  Index(fields: ['tags'], type: IndexType.nonUnique),
  Index(fields: ['description'], type: IndexType.fullText),
  Index(fields: ['price', 'publisher']),
])
class Book with _$BookEntityMixin {
  // id field
  @Id(fieldName: 'book_id', embeddedFields: ['isbn', 'book_name'])
  @DocumentKey(alias: 'book_id')
  BookId? bookId;

  String? publisher;
  double? price;
  List<String> tags = [];
  String? description;

  Book([
    this.bookId,
    this.publisher,
    this.price,
    this.tags = const [],
    this.description,
  ]);
}

// composite id class
@Convertable()
class BookId {
  String? isbn;

  // set a different field name in the document
  @DocumentKey(alias: "book_name")
  String? name;

  // ignore the field in the document
  @IgnoredKey()
  String? author;
}
0
likes
130
pub points
19%
popularity

Publisher

verified publisherdizitart.com

Nitrite entity generator. Automatically generates Nitrite entities from Dart classes.

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

Apache-2.0 (LICENSE)

Dependencies

analyzer, build, build_config, code_builder, collection, dart_style, nitrite, source_gen

More

Packages that depend on nitrite_generator