@textile/hub > ReadTransaction
ReadTransaction class
ReadTransaction performs a read-only bulk transaction on the underlying store.
Signature:
export declare class ReadTransaction extends Transaction<ReadTransactionRequest, ReadTransactionReply>
Extends: Transaction<ReadTransactionRequest, ReadTransactionReply>
Example
Create a new entry and check for it within a transaction
import {Client, ThreadID} from '@textile/hub'
interface Astronaut {
name: string
missions: number
_id: string
}
async function createAndCheck (client: Client, threadID: ThreadID) {
const buzz: Astronaut = {
name: 'Buzz',
missions: 2,
_id: '',
}
const ids = await client.create(threadID, 'astronauts', [buzz])
// Create and start transaction
const t = client.readTransaction(threadID, 'astronauts')
await t.start()
const has = await t.has(ids)
console.log(has) // true
await t.end() // Finish
}
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(context, client, threadID, modelName) | Constructs a new instance of the ReadTransaction class |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
client | grpc.Client<ReadTransactionRequest, ReadTransactionReply> | ||
context | ContextInterface | ||
modelName | string | ||
threadID | ThreadID |
Methods
Method | Modifiers | Description |
---|---|---|
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. | |
start() | start begins the transaction. All operations between start and end will be applied as a single transaction upon a call to end. |