-
Notifications
You must be signed in to change notification settings - Fork 212
/
lib.rs
70 lines (58 loc) 路 1.6 KB
/
lib.rs
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
66
67
68
69
70
mod error;
use core::fmt;
use datamodel::Datamodel;
pub use error::{ConnectorError, ErrorKind};
use serde::*;
use serde_json::Value;
pub type ConnectorResult<T> = Result<T, ConnectorError>;
#[async_trait::async_trait]
pub trait IntrospectionConnector: Send + Sync + 'static {
async fn list_databases(&self) -> ConnectorResult<Vec<String>>;
async fn get_metadata(&self) -> ConnectorResult<DatabaseMetadata>;
async fn get_database_description(&self) -> ConnectorResult<String>;
async fn introspect(&self) -> ConnectorResult<IntrospectionResult>;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct DatabaseMetadata {
pub table_count: usize,
pub size_in_bytes: usize,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub enum Version {
NonPrisma,
Prisma1,
Prisma11,
Prisma2,
}
#[derive(Debug)]
pub struct IntrospectionResult {
/// Datamodel
pub datamodel: Datamodel,
/// warnings
pub warnings: Vec<Warning>,
/// version
pub version: Version,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Warning {
pub code: i8,
pub message: String,
pub affected: Value,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct IntrospectionResultOutput {
/// Datamodel
pub datamodel: String,
/// warnings
pub warnings: Vec<Warning>,
}
impl fmt::Display for IntrospectionResultOutput {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{{\"datamodel\": \"{}\", \"warnings\": {}}}",
self.datamodel,
serde_json::to_string(&self.warnings).unwrap()
)
}
}