Database class

A set of collections (Collection).

An example:

Future<void> main() async {
  // Use an in-memory database
  final database = MemoryDatabaseAdapter().database();

  // Our collection
  final collection = database.collection('pizzas');

  // Our document
  final document = collection.newDocument();

  await document.insert({
    'name': 'Pizza Margherita',
    'rating': 3.5,
    'ingredients': ['dough', 'tomatoes'],
    'similar': [
      database.collection('recipes').document('pizza_funghi'),
    ],
  });
  print('Successfully inserted pizza.');

  await document.patch({
    'rating': 4.5,
  });
  print('Successfully patched pizza.');

  await document.delete();
  print('Successfully deleted pizza.');
}

Constructors

Database()
Database.withAdapter(DatabaseAdapter adapter)
Returns a database that uses the database adapter.
factory

Properties

adapter DatabaseAdapter
Database adapter that implements operations for this database.
read-only
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
sqlClient SqlClient
Returns SQL client. The method returns a valid client even if the underlying database doesn't support SQL.
read-only

Methods

checkHealth({Duration timeout}) Future<void>
Checks that the database can be used. [...]
collection(String collectionId) Collection
Returns a collection with the name. [...]
newWriteBatch() WriteBatch
Return a new write batch. This should always succeed. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
runInTransaction({Reach reach, Duration timeout, Future<void> callback(Transaction transaction)}) Future<void>
Runs a transaction. [...]
toString() String
Returns a string representation of this object.
override

Operators

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