Skip to main content

Connection

Struct Connection 

Source
pub struct Connection { /* private fields */ }
Expand description

A database connection. Supports reading (query) and writing (execute), over a file or in memory.

Implementations§

Source§

impl Connection

Source

pub fn open_vfs(vfs: &dyn Vfs, path: &str) -> Result<Connection>

Open an existing database for reading and writing through vfs. Creates (and recovers from) a <path>-journal companion file.

Source

pub fn open_readonly_vfs(vfs: &dyn Vfs, path: &str) -> Result<Connection>

Open an existing database read-only through vfs. If a <path>-wal file is present, its committed frames are overlaid so WAL-mode databases read correctly.

Source

pub fn create_vfs( vfs: &dyn Vfs, path: &str, page_size: u32, ) -> Result<Connection>

Create a new, empty database through vfs.

Source

pub fn open(path: &str) -> Result<Connection>

Available on crate feature std only.

Open an existing database file for reading and writing (requires std).

Source

pub fn open_readonly(path: &str) -> Result<Connection>

Available on crate feature std only.

Open an existing database file read-only (requires std).

Source

pub fn create(path: &str) -> Result<Connection>

Available on crate feature std only.

Create a new database file with the default 4096-byte page size (std).

Source

pub fn open_memory() -> Result<Connection>

Create a fresh in-memory database (:memory:), always available.

Source

pub fn schema(&self) -> &Schema

The schema catalog.

Source

pub fn query(&self, sql: &str) -> Result<QueryResult>

Run a single SELECT and return all rows.

Source

pub fn query_params(&self, sql: &str, params: &Params) -> Result<QueryResult>

Like query but with bound parameters.

Source

pub fn execute(&mut self, sql: &str) -> Result<usize>

Execute a single non-SELECT statement, returning the number of rows affected (0 for DDL and transaction control).

Source

pub fn execute_params(&mut self, sql: &str, params: &Params) -> Result<usize>

Like execute but with bound parameters.

Trait Implementations§

Source§

impl Subqueries for Connection

Source§

fn scalar(&self, select: &Select, outer: &EvalCtx<'_>) -> Result<Value>

First column of the first row (NULL if no rows) — a scalar subquery. The enclosing row context outer is made available so correlated subqueries can resolve outer columns.
Source§

fn column(&self, select: &Select, outer: &EvalCtx<'_>) -> Result<Vec<Value>>

First column of every row — the candidate set for IN (SELECT …).
Source§

fn exists(&self, select: &Select, outer: &EvalCtx<'_>) -> Result<bool>

Whether the subquery returns at least one row — for EXISTS.
Source§

fn resolve_outer(&self, table: Option<&str>, name: &str) -> Option<Value>

Resolve a column against the enclosing (outer) query rows, if any are in scope. Returns None when there is no such outer column.

Auto Trait Implementations§

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