When writing data to OrbisDB, users are interacting with the underlying decentralized data network, Ceramic. Find out more about the data flow in our Writing data section (link).

Before using the methods, make sure to initialize (link) your OrbisDB SDK and authenticate (link) the user.

Syntax

Single and bulk inserts share the same syntax with the exception of partial failure possibility in case of bulk inserts.

OrbisDB statements work on the principle of “method chaining” to build and eventually execute the query.

Single insert

const result = await orbis
    .insert("MODEL_ID" | "MODEL_ALIAS")
    .value(
        {
            column: value,
            column2: value2,
        }
    )
    .run()

Bulk insert

Bulk statements DO NOT throw, as they are executed in parallel. This means you can have partial failure with only some rows being written.

const { success, errors } = await orbis
    .insertBulk("MODEL_ID" | "MODEL_ALIAS")
    .values(
        {
            column: value,
            column2: value2,
        },
        {
            column: value,
            column2: value2,
        }
    )
    .run()

if(errors.length){
    console.error("Errors occurred during execution", errors)
}

console.log(success)

Contexts

INSERT statements can be scoped to a Context (link) by using .context().

const result = await orbis
    .insert("MODEL_ID" | "MODEL_ALIAS")
    .value(
        {
            column: value,
            column2: value2,
        }
    )
    .context("CONTEXT_ID")
    .run()

Statement execution

You do not have to execute the statement immediately. It’s done by either chaining the .run() or executing it later.

If you decide to postpone the execution, you can access a history of all query runs by accessing the statement.runs property.

Immediate execution

const result = await orbis
    .insert("MODEL_ID" | "MODEL_ALIAS")
    .value(
        {
            column: value,
            column2: value2,
        }
    )
    .run()

Postponed execution

const statement = orbis
    .insert("MODEL_ID" | "MODEL_ALIAS")
    .value(
        {
            column: value,
            column2: value2,
        }
    )

const result = await statement.run()

console.log(result)

// Log the execution history of this statement
console.log(statement.runs)