pub struct Transaction<'a> { /* private fields */ }Expand description
A kit transaction.
Implementations§
Source§impl<'a> Transaction<'a>
impl<'a> Transaction<'a>
Sourcepub fn insert(&mut self, table: &str, row: Map<String, Value>) -> Result<Row>
pub fn insert(&mut self, table: &str, row: Map<String, Value>) -> Result<Row>
Insert a row into table.
pub fn insert_returning( &mut self, table: &str, row: Map<String, Value>, returning: Vec<String>, ) -> Result<Value>
Sourcepub fn insert_many(
&mut self,
table: &str,
rows: Vec<Map<String, Value>>,
) -> Result<Vec<Row>>
pub fn insert_many( &mut self, table: &str, rows: Vec<Map<String, Value>>, ) -> Result<Vec<Row>>
Insert many rows into table within this single transaction.
Each row still passes through defaults, validation, and constraint checks,
but the whole batch is staged in one transaction (the caller commits once)
— far faster than a row-at-a-time begin/commit loop for bulk loads. For a
single-column primary key the existing primary keys are loaded once into a
set so the per-row duplicate check stays O(1) instead of re-scanning the
table for every row. Mirrors the TypeScript kit’s insertInto().valuesMany.
Sourcepub fn update(
&mut self,
table: &str,
pk: &Value,
patch: Map<String, Value>,
) -> Result<Row>
pub fn update( &mut self, table: &str, pk: &Value, patch: Map<String, Value>, ) -> Result<Row>
Update the row in table identified by pk with patch.
Sourcepub fn delete(&mut self, table: &str, pk: &Value) -> Result<()>
pub fn delete(&mut self, table: &str, pk: &Value) -> Result<()>
Delete the row in table identified by pk.
pub fn truncate(&mut self, table: &str) -> Result<()>
pub fn upsert( &mut self, table: &str, row: Map<String, Value>, on_conflict: OnConflict, returning: Vec<String>, ) -> Result<Value>
pub fn update_where( &mut self, table: &str, filter: Option<Expr>, patch: Map<String, Value>, returning: Vec<String>, ) -> Result<Vec<Value>>
pub fn delete_where( &mut self, table: &str, filter: Option<Expr>, returning: Vec<String>, ) -> Result<Vec<Value>>
Sourcepub fn get_by_pk(&self, table: &str, pk: &Value) -> Result<Option<Row>>
pub fn get_by_pk(&self, table: &str, pk: &Value) -> Result<Option<Row>>
Read a row by primary key.
Sourcepub fn select(&self, query: &Query) -> Result<Vec<Row>>
pub fn select(&self, query: &Query) -> Result<Vec<Row>>
Execute a Select query. Subqueries (IN (subquery), EXISTS) and
like/contains/not in predicates resolve against this transaction’s
read snapshot, so they may reference other tables.
Sourcepub fn select_distinct(&self, query: &Query) -> Result<Vec<Row>>
pub fn select_distinct(&self, query: &Query) -> Result<Vec<Row>>
Like select but drops duplicate rows. When the select
projects columns, duplicates are decided on the projection (true
SELECT DISTINCT col, ...); otherwise on the whole row.
Sourcepub fn select_with(&self, ctes: &[Cte], body: &Select) -> Result<Vec<Row>>
pub fn select_with(&self, ctes: &[Cte], body: &Select) -> Result<Vec<Row>>
Materialize each CTE in order (a later CTE may read an earlier one) and
run body with those named results available as virtual tables.
Sourcepub fn aggregate(&self, query: &AggregateQuery) -> Result<Vec<Row>>
pub fn aggregate(&self, query: &AggregateQuery) -> Result<Vec<Row>>
Run an aggregate / group-by / having query. Returns one row per group
(group-key columns plus the aggregate aliases); with no group_by the
whole filtered table is a single group.
Sourcepub fn join(&self, query: &JoinQuery) -> Result<Vec<JoinRow>>
pub fn join(&self, query: &JoinQuery) -> Result<Vec<JoinRow>>
Run a nested-loop join. Each result row is a map keyed by table alias; see
JoinQuery for the shape. Supports inner, left, and cross joins.
Sourcepub fn ann_search(
&self,
table: &str,
column: &str,
query: Vec<f32>,
k: usize,
) -> Result<Vec<Row>>
pub fn ann_search( &self, table: &str, column: &str, query: Vec<f32>, k: usize, ) -> Result<Vec<Row>>
Approximate nearest-neighbour search: return the k rows whose
Embedding column is closest to query, resolved by the column’s ANN
(HNSW) index. Requires an Ann index on column. Results are the top-k
survivor rows (as a set — distance ranking is not currently surfaced).
Sourcepub fn sparse_match(
&self,
table: &str,
column: &str,
query: Vec<(u32, f32)>,
k: usize,
) -> Result<Vec<Row>>
pub fn sparse_match( &self, table: &str, column: &str, query: Vec<(u32, f32)>, k: usize, ) -> Result<Vec<Row>>
Learned-sparse (SPLADE-style) retrieval: return the k rows whose
Sparse column best matches the weighted query tokens query
((token_id, weight) pairs), resolved by the column’s sparse index.
Requires a Sparse index on column.
pub fn execute(&mut self, query: &Query) -> Result<Vec<Value>>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Transaction<'a>
impl<'a> !UnwindSafe for Transaction<'a>
impl<'a> Freeze for Transaction<'a>
impl<'a> Send for Transaction<'a>
impl<'a> Sync for Transaction<'a>
impl<'a> Unpin for Transaction<'a>
impl<'a> UnsafeUnpin for Transaction<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more