1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*use std::fs::File;
use std::io::{Read, Write};
use std::sync::Arc;
use async_trait::async_trait;
use bytes::Bytes;
use futures::Stream;
use crate::models::PostgresDatabase;
use crate::storage::CopyDestination;
use tar::Builder;
use tokio::sync::{Mutex};
use crate::{BaseCopyTarget, DataFormat, PostgresSchema, PostgresTable, Result, TableData};
pub struct ElefantFileDestinationStorage<F: Read + Write + Send> {
archive: Arc<Mutex<Builder<F>>>,
}
impl<F: Read + Write + Send> ElefantFileDestinationStorage<F> {
pub fn new(file_path: &str) -> Result<ElefantFileDestinationStorage<File>> {
let file = File::create(file_path)?;
let archive = Builder::new(file);
Ok(ElefantFileDestinationStorage {
archive: Arc::new(Mutex::new(archive)),
})
}
}
#[async_trait]
impl<F: Read + Write + Send> BaseCopyTarget for ElefantFileDestinationStorage<F> {
async fn supported_data_format(&self) -> Result<Vec<DataFormat>> {
Ok(vec![
DataFormat::Text,
DataFormat::PostgresBinary {
postgres_version: None,
},
])
}
}
#[async_trait]
impl<F: Read + Write + Send> CopyDestination for ElefantFileDestinationStorage<F> {
async fn apply_structure(&mut self, db: &PostgresDatabase) -> Result<()> {
let mut archive = self.archive.lock().await;
archive.
todo!()
}
async fn apply_data<S: Stream<Item=Result<Bytes>> + Send>(&mut self, schema: &PostgresSchema, table: &PostgresTable, data: TableData<S>) -> Result<()> {
todo!()
}
async fn apply_post_structure(&mut self, _db: &PostgresDatabase) -> Result<()> {
Ok(())
}
}*/