pglite_oxide/pglite/
interface.rs1use std::collections::HashMap;
2use std::sync::Arc;
3
4use serde_json::Value;
5
6use crate::protocol::messages::{BackendMessage, NoticeMessage};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum RowMode {
11 Object,
12 Array,
13}
14
15pub type DebugLevel = u8;
17
18pub type TypeParser = Arc<dyn Fn(&str, i32) -> Value + Send + Sync>;
21pub type Serializer = Arc<dyn Fn(&Value) -> anyhow::Result<String> + Send + Sync>;
22pub type NoticeCallback = Arc<dyn Fn(&NoticeMessage) + Send + Sync>;
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub enum DataTransferContainer {
26 Cma,
27 File,
28}
29
30pub type ParserMap = HashMap<i32, TypeParser>;
31pub type SerializerMap = HashMap<i32, Serializer>;
32
33#[derive(Default, Clone)]
34pub struct QueryOptions {
35 pub row_mode: Option<RowMode>,
36 pub parsers: ParserMap,
37 pub serializers: SerializerMap,
38 pub blob: Option<Vec<u8>>,
39 pub param_types: Vec<i32>,
40 pub on_notice: Option<NoticeCallback>,
41 pub data_transfer_container: Option<DataTransferContainer>,
42}
43
44#[derive(Debug, Clone)]
45pub struct FieldInfo {
46 pub name: String,
47 pub data_type_id: i32,
48}
49
50#[derive(Debug, Clone)]
51pub struct Results {
52 pub rows: Vec<Value>,
53 pub fields: Vec<FieldInfo>,
54 pub affected_rows: Option<usize>,
55 pub blob: Option<Vec<u8>>,
56}
57
58#[derive(Clone)]
59pub struct ExecProtocolOptions {
60 pub sync_to_fs: bool,
61 pub throw_on_error: bool,
62 pub on_notice: Option<NoticeCallback>,
63 pub data_transfer_container: Option<DataTransferContainer>,
64}
65
66impl ExecProtocolOptions {
67 pub const fn no_sync() -> Self {
68 Self {
69 sync_to_fs: false,
70 throw_on_error: true,
71 on_notice: None,
72 data_transfer_container: None,
73 }
74 }
75}
76
77impl Default for ExecProtocolOptions {
78 fn default() -> Self {
79 Self {
80 sync_to_fs: true,
81 throw_on_error: true,
82 on_notice: None,
83 data_transfer_container: None,
84 }
85 }
86}
87
88#[derive(Debug, Clone)]
89pub struct ExecProtocolResult {
90 pub messages: Vec<BackendMessage>,
91}
92
93#[derive(Clone)]
94pub struct DescribeQueryParam {
95 pub data_type_id: i32,
96 pub serializer: Option<Serializer>,
97}
98
99#[derive(Clone)]
100pub struct DescribeResultField {
101 pub name: String,
102 pub data_type_id: i32,
103 pub parser: Option<TypeParser>,
104}
105
106#[derive(Clone)]
107pub struct DescribeQueryResult {
108 pub query_params: Vec<DescribeQueryParam>,
109 pub result_fields: Vec<DescribeResultField>,
110}