Skip to main content

Transaction

Extends

Properties

PropertyTypeDescription
commit() => Promise<void>Commit multiple changes to the local DB using the Transaction context.
rollback() => Promise<void>Roll back multiple attempted changes using the Transaction context.

Methods

execute()

execute<T>(query, params?): Promise<QueryResult<T>>;

Execute a SQL write (INSERT/UPDATE/DELETE) query and optionally return results.

When using the default client-side JSON-based view system, the returned result's rowsAffected may be 0 for successful UPDATE and DELETE statements. Use a RETURNING clause and inspect result.rows when you need to confirm which rows changed.

Type Parameters

Type ParameterDefault type
TSqliteRecord

Parameters

ParameterType
querystring
params?any[]

Returns

Promise<QueryResult<T>>

The query result as an object with structured key-value pairs

Inherited from

LockContext.execute


executeBatch()

executeBatch(query, params?): Promise<QueryResult<never>>;

Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set and optionally return results. This is faster than executing separately with each parameter set.

Parameters

ParameterTypeDefault value
querystringundefined
paramsany[][][]

Returns

Promise<QueryResult<never>>

The query result

Inherited from

LockContext.executeBatch


executeRaw()

abstract executeRaw<T>(query, params?): Promise<RawQueryResult>;

Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing. This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.

Type Parameters

Type Parameter
T

Parameters

ParameterType
querystring
params?any[]

Returns

Promise<RawQueryResult>

The RawQueryResult representing each row as an array.

Inherited from

LockContext.executeRaw


get()

get<T>(sql, parameters?): Promise<T>;

Execute a read-only query and return the first result, error if the ResultSet is empty.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
sqlstringThe SQL query to execute
parameters?any[]Optional array of parameters to bind to the query

Returns

Promise<T>

The first result matching the query

Throws

Error if no rows are returned

Inherited from

LockContext.get


getAll()

getAll<T>(sql, parameters?): Promise<T[]>;

Execute a read-only query and return results.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
sqlstringThe SQL query to execute
parameters?any[]Optional array of parameters to bind to the query

Returns

Promise<T[]>

An array of results

Inherited from

LockContext.getAll


getOptional()

getOptional<T>(sql, parameters?): Promise<T | null>;

Execute a read-only query and return the first result, or null if the ResultSet is empty.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
sqlstringThe SQL query to execute
parameters?any[]Optional array of parameters to bind to the query

Returns

Promise<T | null>

The first result if found, or null if no results are returned

Inherited from

LockContext.getOptional