@textile/hub > WriteTransaction
WriteTransaction class
WriteTransaction performs a mutating bulk transaction on the underlying store.
Signature:
export declare class WriteTransaction extends Transaction<WriteTransactionRequest, WriteTransactionReply>
Extends: Transaction<WriteTransactionRequest, WriteTransactionReply>
Example 1
Create a new entry in our collection
import {Client, ThreadID} from '@textile/hub'
interface Astronaut {
name: string
missions: number
_id: string
}
async function createBuzz (client: Client, threadID: ThreadID) {
const buzz: Astronaut = {
name: 'Buzz',
missions: 2,
_id: '',
}
const t = client.writeTransaction(threadID, 'astronauts')
await t.start()
await t.create([buzz])
await t.end() // Commit
}
Example 2
Abort an in-flight transaction
import {Client, ThreadID} from '@textile/hub'
interface Astronaut {
name: string
missions: number
_id: string
}
async function createBuzz (client: Client, threadID: ThreadID) {
const buzz: Astronaut = {
name: 'Buzz',
missions: 2,
_id: '',
}
const t = client.writeTransaction(threadID, 'astronauts')
await t.start()
await t.create([buzz])
await t.discard() // Abort
await t.end()
}
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(context, client, threadID, modelName) | Constructs a new instance of the WriteTransaction class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
client | grpc.Client<WriteTransactionRequest, WriteTransactionReply> | ||
context | ContextInterface | ||
modelName | string | ||
threadID | ThreadID |
Methods
Method | Modifiers | Description |
---|---|---|
create(values) | create creates a new model instance in the given store. | |
delete(IDs) | delete deletes an existing model instance from the given store. | |
discard() | Discard drops all active transaction changes. It also invalidates the transaction, so it will fail upon calling end. | |
find(query) | find queries the store for entities matching the given query parameters. See Query for options. | |
findByID(ID) | findByID queries the store for the id of an instance. | |
has(IDs) | has checks whether a given instance exists in the given store. | |
save(values) | save saves changes to an existing model instance in the given store. | |
start() | start begins the transaction. All operations between start and end will be applied as a single transaction upon a call to end. | |
verify(values) | verify verifies existing instance changes. |