Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction<'a> { /* private fields */ }
Expand description

A kit transaction.

Implementations§

Source§

impl<'a> Transaction<'a>

Source

pub fn insert(&mut self, table: &str, row: Map<String, Value>) -> Result<Row>

Insert a row into table.

Source

pub fn insert_returning( &mut self, table: &str, row: Map<String, Value>, returning: Vec<String>, ) -> Result<Value>

Source

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.

Source

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.

Source

pub fn delete(&mut self, table: &str, pk: &Value) -> Result<()>

Delete the row in table identified by pk.

Source

pub fn truncate(&mut self, table: &str) -> Result<()>

Source

pub fn upsert( &mut self, table: &str, row: Map<String, Value>, on_conflict: OnConflict, returning: Vec<String>, ) -> Result<Value>

Source

pub fn update_where( &mut self, table: &str, filter: Option<Expr>, patch: Map<String, Value>, returning: Vec<String>, ) -> Result<Vec<Value>>

Source

pub fn delete_where( &mut self, table: &str, filter: Option<Expr>, returning: Vec<String>, ) -> Result<Vec<Value>>

Source

pub fn get_by_pk(&self, table: &str, pk: &Value) -> Result<Option<Row>>

Read a row by primary key.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

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).

Source

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.

Source

pub fn execute(&mut self, query: &Query) -> Result<Vec<Value>>

Source

pub fn commit(self) -> Result<()>

Commit the transaction.

A transaction that staged a large batch on some table (typically via Self::insert_many) flushes that table afterward. Without this, a committed-but-unflushed batch exists only as WAL records: every subsequent Database::open (there is no warm/daemon mode for the CLI, and any short-lived process pays this on every invocation) must fully replay and re-index the whole batch just to open the table, which is far more expensive than the one-time flush. Below the threshold this is a no-op cost (the loop below runs over self.staged, already in memory) so ordinary interactive transactions are unaffected.

Source

pub fn rollback(self)

Roll back the transaction.

Source

pub fn all_rows(&self, table: &str) -> Result<Vec<Row>>

All rows of table visible to this transaction (staged writes included).

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.