Skip to main content
Version: Next

Transaction

Transactions are the unique way to apply a list of operations to the datacloud. A transaction can be merged into another transaction so that both are executed as a single set of operations.

All the operations for a transaction are executed atomically. Either all operations succeed, or none is applied.

There are 5 types of basic operations :

  • Create instance: create a node in the database with specified properties.
  • Update instance property: update an existing node in the database.
  • Delete instance: delete a node from the database. Delete only works if all the relations are removed too. Cascade delete can be activated.
  • Create relation: create a relation of a specific type between 2 existing node.
  • Delete relation: remove the specified relation between 2 specified nodes.

In most cases, we apply the Transactions operations using the “execute()” method. The transaction size is limited but in real-time. It notifies observers of the data in real-time.

Larger transactions with big set of operations (batch updates) must be executed using “executeAsLarge()” method. However no notification will be generated.

Callbacks can be registered on transaction using “afterExecution()” method. They are executed once the transaction is applied.

Example of transaction:

const tx = new Transaction(true);
const myNewInstanceTag = tx.create(<myModelTag>);
tx.update(myNewInstanceTag, <myPropertyTag>, <myPropertyValue>)
.execute()
.then(() => {
// success tx case
})
.catch((err) => {
// error during tx case
})

Concurrency transactions do not guarantee their execution order.

Index

Constructors

constructor

Methods

afterExecution

  • afterExecution(callback: (success: boolean, message?: string) => void): Transaction
  • Set a callback to be executed after all the operations in the transaction were executed successfully


    Parameters

    • callback: (success: boolean, message?: string) => void

      the callback to be executed

    Returns Transaction

    this transaction

create

  • create(model: Tag, properties?: Map<Tag, any>, source?: string, tag?: string): string
  • Create a new instance.

    A custom map can specify property values for the instance.

    A source can be the orchestrator (‘server’), local (‘self’) or an external data source (tag of DBConnector). The source is where the object is persisted and its true value outside local scopes.


    Parameters

    • model: Tag

      tag of the model of the instance to be created

    • optionalproperties: Map<Tag, any>

      custom map from tag to their value for properties of the instance to be created

    • optionalsource: string

      optional source of the instance

    • optionaltag: string

      optional tag of the instance to be created and must be unique

    Returns string

    the tag of the instance to be created

createRelation

  • Create relation between two instances


    Parameters

    • relation: Tag

      tag of the relation to be created

    • from: Tag

      tag of the ORIGIN instance of the relation

    • to: Tag

      tag ofo the DESTINATION instance of the relation

    Returns Transaction

    this transaction with the create relation operation registered

delete

  • Delete an instance


    Parameters

    • instance: Tag

      tag of the instance to be deleted

    Returns Transaction

    this transaction

deleteAllRelations

  • Delete any number of the relation starting from specified node.

    The specified node might be the origin or (exclusive) the destination of the relation.

    For the relations :

    - a - [rel1] -> b,
    - c - [inverseRel(rel1)] -> a,
    - a - [rel1] -> d,
    - a - [rel2] -> d

    tx.deleteAllRelation(rel1, a) will remove the first and third relations


    Parameters

    • relation: Relation<any, any>

      deleted relation, indicates relation tag and direction

    • origin: Tag

      starting node

    Returns Transaction

deleteRelation

  • Delete a relation between two specified instances.

    The relation is only deleted for the relation parameter direction.


    Parameters

    • relation: Tag

      tag of the relation to be deleted

    • from: Tag

      origin instance tag

    • to: Tag

      destination instance tag

    Returns Transaction

    this transaction

execute

  • execute(): Promise<void>
  • Execute atomically the transaction at the source


    Returns Promise<void>

    promise resolving if the transaction succeeds, rejecting if the transaction fails

executeAsLarge

  • executeAsLarge(): Promise<void>
  • Execute atomically a transaction at the source The large mode sends the transaction over HTTP


    Returns Promise<void>

    promise resolving if the transaction succeeds, rejecting if the transaction fails.

getId

  • getId(): string
  • Get the transaction id attached to this transaction


    Returns string

    this transaction id

merge

  • Add all operations of another transaction into this transaction


    Parameters

    • otherTransaction: Transaction

      the other transaction to add operations from

    Returns Transaction

    this transaction

model

  • model(tag: Tag): string
  • Retrieve the tag of the model of the instance tag from the created instances in this transaction or from the local database.


    Parameters

    • tag: Tag

      the instance to find the model of

    Returns string

    the tag of the model of the given instance

multiUpdate

  • Update multiple properties of a single instance


    Parameters

    • instance: Tag

      tag of the instance to be updated

    • properties: Map<Tag, any>

      map of properties to update

    Returns Transaction

    this transaction

persist

  • Change the persistence mode of all instances in this transaction


    Parameters

    • optionalpersist: boolean

      whether instances are persisted outside the local datacloud

    Returns Transaction

    this transaction

persistInstance

  • Change the persistence mode for a single instance in this transaction


    Parameters

    • instance: Tag

      the instance to be persisted

    • optionalpersist: boolean

      the persisting mode

    Returns Transaction

    this transaction

setSource

  • Change the source of all instances created in this transaction

    source can be specified as :

    1. the orchestrator (‘server’),
    2. local (‘self’) or
    3. an external data source (Tag of a DBConnector)

    The source of a data object is where the object is persisted.

    By default, the source is the default source configured in the project.


    Parameters

    • source: string

      the new source for instances

    Returns Transaction

    this transaction

update

  • Update the property of an instance


    Type parameters

    • T

    Parameters

    • instance: Tag

      tag of the instance to be updated

    • optionalproperty: Property<T>

      the property to be updated

    • optionalvalue: T

      the value of the property to be updated to

    Returns Transaction

    this transaction

staticfrom

  • Start a transaction using an existing transaction in the provided context or a new one if there is none.


    Parameters

    Returns Transaction

    transaction

staticprocess

  • Execute a given transaction if there is no open transaction in the context.


    Parameters

    Returns Promise<boolean>

    boolean indicating if the argument transaction has been processed