pub struct SqliteDataset<I> { /* private fields */ }dataset and sqlite and std only.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§
Source§impl<I> SqliteDataset<I>
impl<I> SqliteDataset<I>
Sourcepub 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§
Source§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>where
PhantomData<I>: Freeze,
impl<I> Send for SqliteDataset<I>where
PhantomData<I>: Send,
impl<I> Sync for SqliteDataset<I>where
PhantomData<I>: Sync,
impl<I> Unpin for SqliteDataset<I>where
PhantomData<I>: Unpin,
impl<I> UnsafeUnpin for SqliteDataset<I>where
PhantomData<I>: UnsafeUnpin,
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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