connectorx/transports/
sqlite_arrow.rs

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