CollectionModelPath constructor
- String path, {
- String? mirror,
- Object? adapter,
- String? endpoint,
- List<
ModelPermissionQuery> ? permission, - List<
ModelPermissionQuery> ? mirrorPermission,
Annotation to create a collection model.
Specify the path for the collection in path.
Use with freezed
, etc.
You can define a query to get the document model in static const document = _$(class name)DocumentQuery()
.
You can define a query to retrieve the collection model in static const collection = _$(class name)CollectionQuery()
.
You can duplicate the same data to another path by defining a path in mirror.
You can specify a default model adapter by specifying adapter.
You can define access rights to the model by specifying permission or mirrorPermission.
Each data can be retrieved with document.mirror
or collection.mirror
and can be loaded
or saved
in the same way.
In addition, by using saveSync
and deleteSync
, data can be saved and deleted synchronously.
It can be used to achieve relationships in NoSQL databases with follow/follow implementations.
コレクションモデルを作成するためのアノテーション。
pathにコレクション用のパスを指定します。
freezed
などと共に利用してください。
static const document = _$(クラス名)DocumentQuery()
にドキュメントモデルを取得するためのクエリを定義できます。
static const collection = _$(クラス名)CollectionQuery()
にコレクションモデルを取得するためのクエリを定義できます。
mirrorにパスを定義すると別のパスに同じデータを複製することができます。
adapterを指定することでデフォルトのモデルアダプターを指定することができます。
permissionやmirrorPermissionを指定するとモデルへのアクセス権を定義することができます。
それぞれのデータはdocument.mirror
やcollection.mirror
で取得でき、同じようにload
やsave
ができるようになります。
さらにsaveSync
やdeleteSync
を利用することで、同期的にデータの保存や削除が行なえます。
フォロー・フォロワーの実装でNoSQLデータベースにおけるリレーションを実現するために利用することが可能です。
@freezed
@formValue
@immutable
@CollectionModelPath("user")
class UserModel with _$UserModel {
const factory UserModel({
@Default("") String name,
@Default("") String description,
}) = _UserModel;
const UserModel._();
factory UserModel.fromJson(Map<String, Object?> json) => _$UserModelFromJson(json);
static const document = _$UserModelDocumentQuery();
static const collection = _$UserModelCollectionQuery();
}
Implementation
const CollectionModelPath(
this.path, {
this.mirror,
this.adapter,
this.endpoint,
this.permission,
this.mirrorPermission,
});