Sanity Library Reference Docs
    Preparing search index...

    Class Transaction

    Hierarchy

    • BaseTransaction
      • Transaction
    Index

    Constructors

    Methods

    • Commit the transaction, returning a promise that resolves to the first mutated document

      Type Parameters

      • R extends Record<string, any>

      Parameters

      • options: TransactionFirstDocumentMutationOptions

        Options for the mutation operation

      Returns Promise<SanityDocument<R>>

    • Commit the transaction, returning a promise that resolves to an array of the mutated documents

      Type Parameters

      • R extends Record<string, any>

      Parameters

      • options: TransactionAllDocumentsMutationOptions

        Options for the mutation operation

      Returns Promise<SanityDocument<R>[]>

    • Commit the transaction, returning a promise that resolves to a mutation result object

      Parameters

      • options: TransactionFirstDocumentIdMutationOptions

        Options for the mutation operation

      Returns Promise<SingleMutationResult>

    • Commit the transaction, returning a promise that resolves to a mutation result object

      Parameters

      • options: TransactionAllDocumentIdsMutationOptions

        Options for the mutation operation

      Returns Promise<MultipleMutationResult>

    • Commit the transaction, returning a promise that resolves to a mutation result object

      Parameters

      Returns Promise<MultipleMutationResult>

    • Creates a new Sanity document. If _id is provided and already exists, the mutation will fail. If no _id is given, one will automatically be generated by the database. The operation is added to the current transaction, ready to be commited by commit()

      Type Parameters

      • R extends Record<string, any> = Record<string, any>

      Parameters

      Returns this

    • Creates a new Sanity document. If a document with the same _id already exists, the create operation will be ignored. The operation is added to the current transaction, ready to be commited by commit()

      Type Parameters

      • R extends Record<string, any> = Record<string, any>

      Parameters

      Returns this

    • Creates a new Sanity document, or replaces an existing one if the same _id is already used. The operation is added to the current transaction, ready to be commited by commit()

      Type Parameters

      • R extends Record<string, any> = Record<string, any>

      Parameters

      Returns this

    • Deletes the document with the given document ID The operation is added to the current transaction, ready to be commited by commit()

      Parameters

      • documentId: string

        Document ID to delete

      Returns this

    • Performs a patch on the given document ID. Can either be a builder function or an object of patch operations. The operation is added to the current transaction, ready to be commited by commit()

      Parameters

      • documentId: string

        Document ID to perform the patch operation on

      • OptionalpatchOps: PatchOperations | PatchBuilder

        Operations to perform, or a builder function

      Returns this

    • Performs a patch on the given selection. Can either be a builder function or an object of patch operations.

      Parameters

      • patch: MutationSelection

        A string representing a document ID, or an object with query and optional params, defining which document(s) to patch

      • OptionalpatchOps: PatchOperations | PatchBuilder

        Operations to perform, or a builder function

      Returns this

    • Adds the given patch instance to the transaction. The operation is added to the current transaction, ready to be commited by commit()

      Parameters

      • patch: Patch

        Patch to execute

      Returns this

    • Clears the transaction of all operations

      Returns this

    • Gets the current transaction ID, if any

      Returns undefined | string

    • Set the ID of this transaction.

      Parameters

      • id: string

        Transaction ID

      Returns this