SchemaEnforcingDatabaseAdapter class

Enforces schema validation on writes.

This class can be useful for detecting programming errors. The schema is loaded from the database adapter tree with document.schema(). If you use a schemaless database, you can define schema in the constructor of this adapter.

Example

import 'package:database/database.dart';

// Database schema
final schema = DatabaseSchema(
  schemas: [
    productSchema,
    productCategorySchema,
  ],
});


final productSchema = CollectionSchema(
  id: 'Product',
  schemaBuilder: () => MapSchema({
    'name': StringSchema(),
    'price': DoubleSchema(),
    'category': DocumentSchema(
      const ['category_id'],
      productCategorySchema,
      const ['id'],
    ),
  }),
);

final productCategorySchema = CollectionSchema(
  id: 'ProductCategory',
  schemaBuilder: () => MapSchema({
    'name': StringSchema(),
    'products': DocumentListSchema(
      const ['id'],
      productSchema,
      const ['category_id'],
    ),
  }),
);

void main() {
  final database = SchemaEnforcingAdapter(
    databaseSchema: schema,
  ).database();
}
Inheritance

Constructors

SchemaEnforcingDatabaseAdapter({@required DatabaseAdapter adapter, @required DatabaseSchema databaseSchema})

Properties

databaseSchema DatabaseSchema
final
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

close() Future<void>
Closes the database adapter.
inherited
database() Database
Returns the database.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
performCheckConnection({Duration timeout}) Future<void>
inherited
performDocumentBatch(DocumentBatchRequest request) Future<void>
inherited
performDocumentDelete(DocumentDeleteRequest request) Future<void>
inherited
performDocumentDeleteBySearch(DocumentDeleteBySearchRequest request) Future<void>
inherited
performDocumentInsert(DocumentInsertRequest request) Future<void>
override
performDocumentRead(DocumentReadRequest request) Stream<Snapshot>
override
performDocumentReadWatch(DocumentReadWatchRequest request) Stream<Snapshot>
override
performDocumentSearch(DocumentSearchRequest request) Stream<QueryResult>
override
performDocumentSearchChunked(DocumentSearchChunkedRequest request) Stream<QueryResult>
inherited
performDocumentSearchWatch(DocumentSearchWatchRequest request) Stream<QueryResult>
override
performDocumentTransaction(DocumentTransactionRequest request) Future<void>
inherited
performDocumentUpdate(DocumentUpdateRequest request) Future<void>
override
performDocumentUpdateBySearch(DocumentUpdateBySearchRequest request) Future<void>
override
performDocumentUpsert(DocumentUpsertRequest request) Future<void>
override
performExtension(DatabaseExtensionRequest<DatabaseExtensionResponse> request) Stream<DatabaseExtensionResponse>
inherited
performSchemaRead(SchemaReadRequest request) Stream<DatabaseSchema>
override
performSqlQuery(SqlQueryRequest request) Future<SqlIterator>
inherited
performSqlStatement(SqlStatementRequest request) Future<SqlStatementResult>
inherited
performSqlTransaction(SqlTransactionRequest request) Future<void>
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited