View Source Appwrite.Services.Database (appwrite v0.2.1)
The Database service allows you to create structured collections of documents, query and filter lists of documents, and manage an advanced set of read and write access permissions.
All the data in the database service is stored in structured JSON documents. The Appwrite database service also allows you to nest child documents in parent documents and use deep filters to both search and query your data.
Each database document structure in your project is defined using the Appwrite collection rules. The collection rules help you ensure all your user-submitted data is validated and stored according to the collection structure.
Using Appwrite's permissions architecture, you can assign read or write access to each document
in your project for either a specific user, team, user role, or grant it with public access (*).
Summary
Functions
Create a new document in a specified collection.
Delete a document by its ID.
Retrieve a document by its ID.
List documents in a specified collection.
Update a document by its ID.
Functions
@spec create_document( String.t(), String.t(), String.t() | nil, map(), [String.t()] | nil ) :: {:ok, Appwrite.Types.Document.t()} | {:error, any()}
Create a new document in a specified collection.
Parameters
database_id(String.t()): The database ID.collection_id(String.t()): The collection ID.document_id(String.t() | nil): The document ID. Auto-generated ifnil.data(map()): Document data as a map.permissions([String.t()] | nil): Optional permission strings.
Returns
{:ok, Document.t()}on success.{:error, reason}on failure.
Delete a document by its ID.
Parameters
database_id(String.t()): The database ID.collection_id(String.t()): The collection ID.document_id(String.t()): The document ID.
Returns
{:ok, %{}}on success.{:error, reason}on failure.
@spec get_document(String.t(), String.t(), String.t(), [String.t()] | nil) :: {:ok, Appwrite.Types.Document.t()} | {:error, any()}
Retrieve a document by its ID.
Parameters
database_id(String.t()): The database ID.collection_id(String.t()): The collection ID.document_id(String.t()): The document ID.queries([String.t()] | nil): Optional list of query strings.
Returns
{:ok, Document.t()}on success.{:error, reason}on failure.
@spec list_documents(String.t(), String.t(), [String.t()] | nil) :: {:ok, Appwrite.Types.DocumentList.t()} | {:error, any()}
List documents in a specified collection.
Parameters
database_id(String.t()): The database ID.collection_id(String.t()): The collection ID.queries([String.t()] | nil): Optional list of query strings.
Returns
{:ok, DocumentList.t()}on success.{:error, reason}on failure.
@spec update_document( String.t(), String.t(), String.t(), map() | nil, [String.t()] | nil ) :: {:ok, Appwrite.Types.Document.t()} | {:error, any()}
Update a document by its ID.
Only the fields included in data are updated; all other fields remain unchanged.
Parameters
database_id(String.t()): The database ID.collection_id(String.t()): The collection ID.document_id(String.t()): The document ID.data(map() | nil): Partial data to update.permissions([String.t()] | nil): Optional updated permission strings.
Returns
{:ok, Document.t()}on success.{:error, reason}on failure.