Struct SqliteDataset
pub struct SqliteDataset<I> { /* private fields */ }Expand description
This struct represents a dataset where all items are stored in an SQLite database. Each instance of this struct corresponds to a specific table within the SQLite database, and allows for interaction with the data stored in the table in a structured and typed manner.
The database is read and written with Turso, which implements the engine
in Rust rather than linking libsqlite3, so the files stay interchangeable with any other SQLite
tooling. Note that this does not make the build free of C: turso pulls simsimd for its SIMD
kernels, which compiles C unconditionally.
The SQLite database must contain a table with the same name as the split field. This table should
have a primary key column named row_id, which is used to index the rows in the table. The row_id
should start at 1, while the corresponding dataset index should start at 0, i.e., row_id = index + 1.
Table columns can be represented in two ways:
- The table can have a column for each field in the
Istruct. In this case, the column names in the table should match the field names of theIstruct. The field names can be a subset of column names and can be in any order.
For the supported field types, refer to
SQLite data types. Each column is handed to serde as
the value its storage class implies: INTEGER as i64, REAL as f64, TEXT as String,
and BLOB as a byte sequence. Booleans are read back from integers, and a nullable column maps
to an Option field. Reading a NULL into a bare f32 or f64 field yields NaN.
A Vec<u8> field derives as a sequence, so a large BLOB column is walked one byte at a time.
Tagging the field #[serde(with = "serde_bytes")] moves the blob across instead, which is
substantially cheaper for columns of any size.
- The fields in the
Istruct can be serialized into a single columnitemin the table. In this case, the table should have a single column nameditemof typeBLOB. This is useful when theIstruct contains complex fields that cannot be mapped to a SQLite type, such as nested structs, vectors, etc. The serialization is done using MessagePack.
Note: The code automatically figures out which of the above two cases is applicable, and uses the appropriate method to read the data from the table.
Implementations§
§impl<I> SqliteDataset<I>
impl<I> SqliteDataset<I>
pub fn from_db_file<P>(
db_file: P,
split: &str,
) -> Result<SqliteDataset<I>, SqliteDatasetError>
pub fn from_db_file<P>( db_file: P, split: &str, ) -> Result<SqliteDataset<I>, SqliteDatasetError>
Initializes a SqliteDataset from a SQLite database file and a split name.
Trait Implementations§
§impl<I> Dataset<I, SqliteDatasetError> for SqliteDataset<I>
impl<I> Dataset<I, SqliteDatasetError> for SqliteDataset<I>
Auto Trait Implementations§
impl<I> !RefUnwindSafe for SqliteDataset<I>
impl<I> !UnwindSafe for SqliteDataset<I>
impl<I> Freeze for SqliteDataset<I>
impl<I> Send for SqliteDataset<I>where
I: Send,
impl<I> Sync for SqliteDataset<I>where
I: Sync,
impl<I> Unpin for SqliteDataset<I>where
I: Unpin,
impl<I> UnsafeUnpin for SqliteDataset<I>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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