neon_wasi_http/
neon_response.rs1use std::{error::Error, fmt::Display};
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Serialize, Deserialize)]
6#[serde(untagged)]
7pub enum TransactionResponse {
8 Ok(TransactionResult),
9 Err(NeonError),
10}
11
12#[derive(Default, Debug, Clone, Serialize, Deserialize)]
13pub struct TransactionResult {
14 pub results: Vec<QueryResult>,
15}
16
17#[derive(Debug, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum QueryResponse {
20 Ok(QueryResult),
21 Err(NeonError),
22}
23
24#[derive(Default, Debug, Clone, Serialize, Deserialize)]
25pub struct QueryResult {
26 pub command: String,
27 #[serde(alias = "rowCount")]
28 pub row_count: i64,
29 pub rows: Vec<serde_json::Value>,
30 pub fields: Vec<Field>,
31 #[serde(alias = "rowAsArray")]
32 pub row_as_array: bool,
33}
34
35#[derive(Default, Debug, Clone, Serialize, Deserialize)]
36pub struct Field {
37 name: String,
38 #[serde(alias = "dataTypeID")]
39 data_type_id: i64,
40 #[serde(alias = "tableID")]
41 table_id: i64,
42 #[serde(alias = "columnID")]
43 column_id: i64,
44 #[serde(alias = "dataTypeSize")]
45 data_type_size: i64,
46 #[serde(alias = "dataTypeModifier")]
47 data_type_modifier: i64,
48 format: String,
49}
50
51#[allow(unused)]
52#[derive(Deserialize, Serialize, Debug)]
53pub struct NeonError {
54 pub message: String,
55 pub code: String,
56 pub detail: Option<String>,
57 pub hint: Option<String>,
58 pub position: String,
59 #[serde(alias = "internalPosition")]
60 pub internal_position: Option<String>,
61 #[serde(alias = "internalQuery")]
62 pub internal_query: Option<String>,
63 pub severity: String,
64 #[serde(alias = "where")]
65 pub location: Option<String>,
66 pub table: Option<String>,
67 pub column: Option<String>,
68 pub schema: Option<String>,
69 pub data_type: Option<String>,
70 pub constraint: Option<String>,
71 pub file: String,
72 pub line: String,
73 pub routine: String,
74}
75
76impl Display for NeonError {
77 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78 f.write_fmt(format_args!("{:#?}", self))
79 }
80}
81
82impl Error for NeonError {}