@squidcloud/client
    Preparing search index...

    Class DocumentReference<T>

    Holds a reference to a document. A document reference is a reference to a specific record in a collection. You can use it to read or write data to the document. A document can refer to a row in a table in a relational database or a document in a NoSQL database. Additionally, a document reference can refer to a non-existent document, which you can use to create a new document.

    Read more about document references in the documentation.

    Type Parameters

    Index

    Properties

    refId: string

    A string that uniquely identifies this document reference.

    Accessors

    • get data(): T

      Returns the document data. Throws an error if the document does not exist.

      Returns T

      The document data.

      Error if the document does not exist.

    • get dataRef(): T

      Returns a read-only internal copy of the document data. This works similar to this.data, except it does not perform a defensive copy. The caller may not modify this object, on penalty of unexpected behavior.

      Returns T

      The document data.

      Error if the document does not exist.

    • get hasData(): boolean

      Returns whether data has been populated for this document reference. Data will not present if a document has not been queried, does not exist, or has been deleted.

      Returns boolean

      Whether the document has data.

    Methods

    • Decrements the value at the given path by the given value. The value may be both positive and negative.

      Parameters

      • path: Paths<T>

        The path to the value to decrement.

      • value: number

        The value to decrement by.

      • OptionaltransactionId: string

        The transaction to use for this operation. If not provided, the operation will be applied immediately.

      Returns Promise<void>

    • Deletes the document. The delete will be reflected optimistically locally and will be applied to the server later. If a transactionId is provided, the delete will be applied to the server as an atomic operation together with the rest of the operations in the transaction and the delete will not reflect locally until the transaction is completed locally.

      The returned promise will resolve once the delete has been applied to the server or immediately if the delete is part of a transaction.

      Parameters

      • OptionaltransactionId: string

        The transaction to use for this operation. If not provided, the operation will be applied immediately.

      Returns Promise<void>

    • Similar to update, but only deletes the given path.

      Parameters

      • path: Paths<T>

        The path to delete.

      • OptionaltransactionId: string

        The transaction to use for this operation. If not provided, the operation will be applied immediately.

      Returns Promise<void>

    • Increments the value at the given path by the given value. The value may be both positive and negative.

      Parameters

      • path: Paths<T>

        The path to the value to increment.

      • value: number

        The value to increment by.

      • OptionaltransactionId: string

        The transaction to use for this operation. If not provided, the operation will be applied immediately.

      Returns Promise<void>

    • Inserts the document with the given data. If the document already exists, the operation will be treated as upsert. The insert will be reflected optimistically locally and will be applied to the server later. If a transactionId is provided, the insert will be applied to the server as an atomic operation together with the rest of the operations in the transaction and the insert will not reflect locally until the transaction is completed locally.

      The returned promise will resolve once the insert has been applied to the server or immediately if the insert is part of a transaction.

      Parameters

      • data: Omit<T, "__id">

        The data to insert.

      • OptionaltransactionId: string

        The transaction to use for this operation. If not provided, the operation will be applied immediately.

      Returns Promise<void>

    • Returns whether the locally available version of the document may not be the latest version on the server.

      Returns boolean

      Whether the locally available version of the document may not be the latest version on the server.

    • Returns the data that is currently available on the client or undefined if data has not yet been populated.

      Returns undefined | T

      The data that is currently available on the client or undefined if data has not yet been populated.

    • Similar to update, but only updates the given path.

      Type Parameters

      • K

      Parameters

      • path: K

        The path to update.

      • value: {
            [k in string | number | symbol]-?: k extends string
            | number
                ?
                    | Record<`${k<k>}`, T[k<k>]>
                    | (
                        Required<T>[k<k>] extends any[]
                            ? never
                            : Required<T>[k<k>] extends object
                                ? {
                                    [k in string | number | symbol]-?: k extends (...)
                                    | (...)
                                        ? (...) | (...)
                                        : never
                                }[keyof any[any]]
                                : never
                    )
                : never
        }[keyof T][K]

        The value to set at the given path.

      • OptionaltransactionId: string

        The transaction to use for this operation. If not provided, the operation will be applied immediately.

      Returns Promise<void>

    • A promise that resolves with the latest data from the server or undefined if the document does not exist on the server.

      Returns Promise<undefined | T>

      A promise that resolves with latest data from the server or undefined if the document does not exist on the server.

    • Returns an observable that emits the latest data from the server or undefined if the document is deleted or does not exist on the server.

      Returns Observable<undefined | T>

      An observable that emits the latest data from the server or undefined if the document is deleted or does not exist on the server.

    • Updates the document with the given data. The update will be reflected optimistically locally and will be applied to the server later. If a transactionId is provided, the update will be applied to the server as an atomic operation together with the rest of the operations in the transaction and the update will not reflect locally until the transaction is completed locally.

      The returned promise will resolve once the update has been applied to the server or immediately if the update is part of a transaction.

      Parameters

      • data: Partial<
            {
                [k in string
                | number
                | symbol]-?: k extends string
                | number
                    ?
                        | Record<`${k<k>}`, T[k<k>]>
                        | (
                            Required<T>[k<k>] extends any[]
                                ? never
                                : Required<T>[k<k>] extends object
                                    ? {
                                        [k in string | number | symbol]-?: k extends (...)
                                        | (...)
                                            ? (...) | (...)
                                            : never
                                    }[keyof any[any]]
                                    : never
                        )
                    : never
            }[keyof T],
        >

        The data to update - can be partial.

      • OptionaltransactionId: string

        The transaction to use for this operation. If not provided, the operation will be applied immediately.

      Returns Promise<void>