database library

Enables access to databases.

The API is designed to support:

  • SQL databases
  • Document databases
  • Search engines

Example

import 'package:database/database.dart';

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.');
}

Raw SQL access

import 'package:database/database.dart';
import 'package:database/sql.dart';
import 'package:database_adapter_postgre/database_adapter_postgre.dart';

Future main() async {
  // Configure a PostgreSQL database connection
  final database = PostgreAdapter(
    // ...
  ).database();

  // Insert rows
  await database.sqlClient.execute(
    'INSERT INTO employee(name) VALUES (?)',
    ['John Doe'],
  );
}

Classes

Blob
A sequence of bytes. The bytes don't need to fit in the memory.
BlobMetadata
Metadata about Blob.
CachingDatabaseAdapter
An adapter that enables caching of data (for example, in local memory). [...]
Collection
A set of documents in a database (Database). [...]
Column<T>
A database column. [...]
ColumnQueryHelper<T>
A helper for building columnar queries. [...]
Database
A set of collections (Collection). [...]
DatabaseExceptionCodes
Date
A date in the Gregorian calendar. It doesn't have a timezone. [...]
Document<T>
A document in a Collection. [...]
GeoPoint
A geographic point on Earth. [...]
Int64
An immutable 64-bit signed integer, in the range -2^63, 2^63 - 1. Arithmetic operations may overflow in order to maintain this range.
MemoryDatabaseAdapter
An adapter that stores data in the local memory. [...]
MultiSorter
Sorts values based on many criteria. Used by Query. [...]
PropertySorter
Sorts values according to value of a map property. [...]
Query
A database query. [...]
QueryBuilder
Builds instances of Query. [...]
QueryResult
The result of sending a Query to a Collection. [...]
QueryResultItem<T>
Item in a QueryResult. [...]
SchemaEnforcingDatabaseAdapter
Enforces schema validation on writes. [...]
SearchEnginePromotingDatabaseAdapter
Forwards eligible search requests to a search engine.
SnaphotBuilder
Builds a Snapshot.
Snapshot
A snapshot of a Document version. [...]
Snippet
Describes a snippet of the document in QueryResultItem.
SnippetSpan
Describes a span in a Snippet.
Sorter
Sorts values. [...]
SuggestedQuery
Describes a suggested query in SearchResponseDetails.
Timestamp
A nanosecond-precision timestamp.
Transaction
WriteBatch
Enables writing many values at once. [...]

Enums

Reach
Describes how far reads/writes should reach before they are good enough. [...]

Exceptions / Errors

BlobReadException
An exception thrown by Blob.
DatabaseException
An exception that may be thrown by Database, Collection, Document, SqlClient, and other database classes. [...]