connectorx/transports/
sqlite_arrowstream.rs

1//! Transport from SQLite Source to Arrow Destination.
2
3use crate::{
4    destinations::arrowstream::{
5        typesystem::ArrowTypeSystem, ArrowDestination, ArrowDestinationError,
6    },
7    impl_transport,
8    sources::sqlite::{SQLiteSource, SQLiteSourceError, SQLiteTypeSystem},
9    typesystem::TypeConversion,
10};
11use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
12use thiserror::Error;
13
14#[derive(Error, Debug)]
15pub enum SQLiteArrowTransportError {
16    #[error(transparent)]
17    Source(#[from] SQLiteSourceError),
18
19    #[error(transparent)]
20    Destination(#[from] ArrowDestinationError),
21
22    #[error(transparent)]
23    ConnectorX(#[from] crate::errors::ConnectorXError),
24}
25
26/// Convert SQLite data types to Arrow data types.
27pub struct SQLiteArrowTransport;
28
29impl_transport!(
30    name = SQLiteArrowTransport,
31    error = SQLiteArrowTransportError,
32    systems = SQLiteTypeSystem => ArrowTypeSystem,
33    route = SQLiteSource => ArrowDestination,
34    mappings = {
35        { Bool[bool]                 => Boolean[bool]           | conversion auto }
36        { Int8[i64]                  => Int64[i64]              | conversion auto }
37        { Int4[i32]                  => Int64[i64]              | conversion auto }
38        { Int2[i16]                  => Int64[i64]              | conversion auto }
39        { Real[f64]                  => Float64[f64]            | conversion auto }
40        { Text[Box<str>]             => LargeUtf8[String]       | conversion option }
41        { Blob[Vec<u8>]              => LargeBinary[Vec<u8>]    | conversion auto }
42        { Date[NaiveDate]            => Date32[NaiveDate]       | conversion auto }
43        { Time[NaiveTime]            => Time64[NaiveTime]       | conversion auto }
44        { Timestamp[NaiveDateTime]   => Date64[NaiveDateTime]   | conversion auto }
45    }
46);
47
48impl TypeConversion<Box<str>, String> for SQLiteArrowTransport {
49    fn convert(val: Box<str>) -> String {
50        val.to_string()
51    }
52}