1pub mod level;
10
11pub use level::NoticeLevel;
12
13#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct SQLNotice {
16 pub level: NoticeLevel,
17 pub sqlstate: String,
18 pub message: String,
19 pub detail: Option<String>,
20 pub hint: Option<String>,
21}
22
23impl SQLNotice {
24 pub fn new(level: NoticeLevel, message: impl Into<String>) -> Self {
26 Self {
27 level,
28 sqlstate: level.default_sqlstate().to_string(),
29 message: message.into(),
30 detail: None,
31 hint: None,
32 }
33 }
34
35 pub fn notice(message: impl Into<String>) -> Self {
37 Self::new(NoticeLevel::Notice, message)
38 }
39
40 pub fn warning(message: impl Into<String>) -> Self {
42 Self::new(NoticeLevel::Warning, message)
43 }
44
45 #[must_use]
47 pub fn with_sqlstate(mut self, sqlstate: impl Into<String>) -> Self {
48 self.sqlstate = sqlstate.into();
49 self
50 }
51
52 #[must_use]
54 pub fn with_detail(mut self, detail: impl Into<String>) -> Self {
55 self.detail = Some(detail.into());
56 self
57 }
58
59 #[must_use]
61 pub fn with_hint(mut self, hint: impl Into<String>) -> Self {
62 self.hint = Some(hint.into());
63 self
64 }
65}