Introducing a new way to review your PRs.

Read the announcement

appwrite / sdk-for-react-native

[READ ONLY] Official Appwrite React Native SDK 💙 ⚛︎

View on GitHub

24 documents · Updated Nov 18, 2026

docs / databases-and-tablesdb-records

Databases, DocumentsDB, and TablesDB records

These services store project data in two record models. DocumentsDB stores documents in collection schemas. TablesDB stores rows in table schemas. The legacy Databases surface keeps the older collection-and-document contract and transaction paths for compatibility. For the wider data service map, see Data files and execution services.

Resource models

The schema choice sets the parent resource and the shape of each record. A database scopes collections and tables. The matching record service uses that parent to validate and return data.

ModelParent pathData shapeList result
DocumentDatabase → collectionJSON data shaped by collection attributesDocumentList.documents
RowDatabase → tableValues shaped by table columnsRowList.rows

Both models include an ID, sequence value, database ID, time fields, permissions, and application data. Documents identify their collection with $collectionId. Rows identify their table with $tableId. The models look similar, but their parent IDs and response lists are not interchangeable.

Schema boundary

Schema management prepares the database before record work starts. The collection or table must exist, and its attributes or columns must be ready before a document or row can be written. The record methods in these services use that schema. They do not define it during a write.

The Databases class is the legacy collection-and-document surface. Its document methods use the database and collection hierarchy and are deprecated in favor of the newer service paths. DocumentsDB provides the standalone document service. TablesDB provides the standalone table service.

References: src/…/databases.ts• L549-575 src/…/documents-db.ts• L543-548 src/…/tables-db.ts• L543-548

Document resources

DocumentsDB represents flexible JSON records inside collections. The standalone DocumentsDB class owns the current document paths and returns Document or DocumentList models. The matching document methods on Databases preserve the older path and model for existing clients.

References: src/…/documents-db.ts• L543-711 src/…/databases.ts• L549-723

Row resources

TablesDB represents typed records inside tables. The standalone TablesDB class returns Row or RowList models and points each result to its table with $tableId. A table must have its columns before a row write can succeed.

References: src/…/tables-db.ts• L543-712

Record operations

Each record model follows the same main lifecycle. The caller selects a database and its collection or table. The caller can then list, create, read, replace, update, or delete a record.

GoalDocumentsDBTablesDBResult
List recordslistDocumentslistRowsMatching records and a total
Create onecreateDocumentcreateRowThe new record
Create or replaceupsertDocumentupsertRowThe created or changed record
Read onegetDocumentgetRowThe selected record
Change selected fieldsupdateDocumentupdateRowThe changed record
Delete onedeleteDocumentdeleteRowAn empty result

The caller supplies the record ID and data for a create. An upsert creates a missing ID or replaces the data for an existing ID. An update changes only the named attributes or columns. Create, upsert, and update can also set permissions. Each write can carry a transaction ID so the service stages it instead of applying it to the committed view.

DocumentsDB also supports bulk document creation. This is a document-only convenience. All documents still belong to one selected collection.

References: src/…/documents-db.ts• L714-1060 src/…/documents-db.ts• L1386-1884 src/…/tables-db.ts• L715-898 src/…/tables-db.ts• L1217-1694

Query reads

Query reads select records from one collection or table. The SDK accepts query strings for list methods and for the POST query methods named createQuery. A list returns matching records and can also return a total count.

The main read controls are:

  • queries filters, sorts, limits, or shapes the selected records.
  • total: false skips the count when the caller does not need it.
  • ttl allows a list response to remain cached for a limited time.
  • transactionId reads the view that includes staged changes.

The list and POST query forms serve the same read goal. The POST form places queries in the request body. This supports larger query lists than a URL can carry. Aggregate, group, distinct, and join queries can return only the selected data. System fields may not be present in every result.

This flow shows how the selected resource and query choose either committed data or a transaction view.

flowchart LR
    A[Database and collection or table] --> B[Query]
    B --> C{transactionId?}
    C -->|No| D[Committed view]
    C -->|Yes| E[Transaction view]
    D --> F[Document list or row list]
    E --> F

List cache entries are tied to the project, selected resource, schema version, caller roles, and exact query. Schema changes invalidate affected entries. Record writes do not. Use ttl: 0 when a list must show fresh data.

References: src/…/documents-db.ts• L543-711 src/…/documents-db.ts• L1062-1234 src/…/tables-db.ts• L543-712 src/…/tables-db.ts• L901-1070 src/…/databases.ts• L549-723

Atomic numeric updates

Atomic numeric updates change one number without a read followed by a full record write. DocumentsDB targets an attribute. TablesDB targets a column. Both return the changed record and can stage the change in a transaction.

ChangeDocumentsDBTablesDBGuard
IncreaseincrementDocumentAttributeincrementRowColumnOptional max
DecreasedecrementDocumentAttributedecrementRowColumnOptional min

The service rejects a change that would pass its bound. This supports counters and stock values without exposing a separate read-and-write race to the caller.

References: src/…/documents-db.ts• L1886-2252 src/…/tables-db.ts• L1696-2056

Transaction operations

A transaction is a short-lived set of staged database operations. The caller creates it, sends record or numeric changes with its ID, may read the staged view, and then commits or rolls back the work.

The transaction flow is:

sequenceDiagram
    participant App as Application
    participant DB as DocumentsDB or TablesDB
    App->>DB: createTransaction(ttl)
    DB-->>App: Pending transaction
    App->>DB: Record or numeric operation with transactionId
    App->>DB: createOperations(transactionId, operations)
    App->>DB: Read with transactionId (optional)
    alt Work is valid
        App->>DB: updateTransaction(commit)
        DB-->>App: Committed transaction
    else Work is abandoned
        App->>DB: updateTransaction(rollback)
        DB-->>App: Rolled-back transaction
    end

DocumentsDB and TablesDB each expose transaction list, create, read, update, delete, and batch-operation actions. Their transaction IDs belong to their matching service family. The legacy Databases class exposes equivalent transaction actions on the older database path. Those actions are deprecated in favor of the newer service paths.

Transactions have a time-to-live. If a transaction expires before its final action, the caller cannot complete the intended commit or rollback flow. A read without the transaction ID uses committed data and does not include staged changes.

References: src/…/documents-db.ts• L16-541 src/…/tables-db.ts• L16-541 src/…/databases.ts• L16-547

Service boundaries

Choose the service that matches the record model and its parent resource. Use DocumentsDB for standalone collection documents. Use TablesDB for table rows. Use Databases only when an existing client still depends on the legacy collection-and-document surface.

NeedService boundary
Manage or read collection documents through the standalone document APIDocumentsDB
Manage or read table rowsTablesDB
Keep an older collection-document client workingDatabases compatibility methods
Search vector documents rather than query database recordsVectorsDB documents and queries

Do not pass a collection ID to a row method or a table ID to a document method. The similar CRUD names hide different parent paths, record types, and list fields.

References: src/…/databases.ts• L549-575 src/…/documents-db.ts• L543-559 src/…/tables-db.ts• L543-559

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the document and row contracts separate. Preserve $collectionId with DocumentList.documents and $tableId with RowList.rows.
  • Keep the standalone service path and transaction path matched. A transaction ID created by one service family must not be silently sent to another.
  • Keep transactionId available across CRUD, numeric updates, and reads when transaction behavior changes.
  • Keep list cache identity aligned with schema version, caller roles, exact query, and the rule that record writes do not invalidate cached lists.
  • Preserve the deprecated Databases document and transaction methods, or update the migration guidance when the preferred service changes.

Important failure modes

TriggerConsequenceGuard
Write before the collection attributes or table columns existThe record write is rejectedPrepare the parent schema before record work
Use a collection ID with a row method or a table ID with a document methodThe request targets the wrong resource model and failsKeep the database, collection, or table IDs paired with their service
Increment above max or decrement below minThe numeric update failsSet bounds to the allowed business range
Read a list from cache after a record writeThe list can contain old data until its TTL endsUse ttl: 0 when the list must be fresh
Read staged data without its transaction IDThe read uses committed data and hides the staged changePass the same transaction ID to the read
Use a transaction after its TTL expiresThe planned commit or rollback cannot completeKeep the transaction short or set a suitable TTL

Key files

FileWhy to read it
src/…/documents-db.tsDefines the standalone document lifecycle, bulk creation, query reads, numeric updates, and document transactions
src/…/tables-db.tsDefines the standalone row lifecycle, query reads, numeric updates, and table transactions
src/…/databases.tsDefines the legacy document and transaction compatibility surface
docs/data-files-and-execution-services.mdPlaces database records beside the other data and execution services
docs/vectorsdb-documents-and-queries.mdExplains the separate vector document and query model