mod compression;
mod options;
mod service;
mod writer;
use std::{
fmt::Debug,
io,
pin::Pin,
task::{Context, Poll},
};
use compression::MaybeCompressedWriter;
use futures_channel::mpsc::{Receiver, Sender};
use futures_io::AsyncWrite;
pub use options::ImportBuilder;
use sqlx_core::bytes::BytesMut;
use crate::etl::{import::service::ImportService, job::OneShotServer};
type ImportDataSender = Sender<BytesMut>;
type ImportDataReceiver = Receiver<BytesMut>;
type ImportChannelSender = flume::Sender<ImportDataSender>;
type ImportPartsReceiver = flume::Receiver<(ImportDataSender, OneShotServer<ImportService>)>;
#[derive(Debug)]
pub struct ExaImport(MaybeCompressedWriter);
impl ExaImport {
fn new(rx: ImportPartsReceiver, buffer_size: usize, with_compression: bool) -> Self {
Self(MaybeCompressedWriter::new(
rx,
buffer_size,
with_compression,
))
}
}
impl AsyncWrite for ExaImport {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
Pin::new(&mut self.0).poll_write(cx, buf)
}
fn poll_write_vectored(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[io::IoSlice<'_>],
) -> Poll<io::Result<usize>> {
Pin::new(&mut self.0).poll_write_vectored(cx, bufs)
}
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Pin::new(&mut self.0).poll_flush(cx)
}
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Pin::new(&mut self.0).poll_close(cx)
}
}
#[derive(Debug, Clone, Copy)]
pub enum Trim {
Left,
Right,
Both,
}
impl AsRef<str> for Trim {
fn as_ref(&self) -> &str {
match self {
Self::Left => "LTRIM",
Self::Right => "RTRIM",
Self::Both => "TRIM",
}
}
}