uqa_sql/ast/
identity_sequence.rs1use super::{RelationPersistence, SequenceDeclaration};
10use crate::SQLError;
11use serde::{Deserialize, Serialize};
12
13#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
15pub struct IdentitySequenceDeclaration {
16 pub name: Option<IdentitySequenceName>,
18 pub persistence: Option<RelationPersistence>,
20 pub sequence: SequenceDeclaration,
22 pub error: Option<DeferredSQLError>,
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28pub struct IdentitySequenceName {
29 pub schema: Option<String>,
30 pub name: String,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
35pub struct DeferredSQLError {
36 pub sqlstate: String,
37 pub message: String,
38 #[serde(default, skip_serializing_if = "Option::is_none")]
39 pub detail: Option<String>,
40 #[serde(default, skip_serializing_if = "Option::is_none")]
41 pub hint: Option<String>,
42}
43
44impl From<&SQLError> for DeferredSQLError {
45 fn from(error: &SQLError) -> Self {
46 Self {
47 sqlstate: error.sqlstate().unwrap_or("XX000").to_string(),
48 message: error.to_string(),
49 detail: error.detail().map(str::to_owned),
50 hint: error.hint().map(str::to_owned),
51 }
52 }
53}
54
55impl From<DeferredSQLError> for SQLError {
56 fn from(error: DeferredSQLError) -> Self {
57 if error.detail.is_some() || error.hint.is_some() {
58 return Self::Diagnostic {
59 sqlstate: error.sqlstate,
60 message: error.message,
61 detail: error.detail,
62 hint: error.hint,
63 };
64 }
65 Self::Routine {
66 sqlstate: error.sqlstate,
67 message: error.message,
68 }
69 }
70}
71
72#[cfg(test)]
73mod tests;