uqa_sql/notice/level.rs
1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! The levels of notices.
8
9/// The level of a notice, as `PostgreSQL` names its message levels below `ERROR`, in increasing order of severity.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub enum NoticeLevel {
12 /// `DEBUG`, which `PL/pgSQL`'s `RAISE DEBUG` reports as `DEBUG1`.
13 Debug,
14 Log,
15 Info,
16 Notice,
17 Warning,
18}
19
20impl NoticeLevel {
21 /// The level's name, as clients show it.
22 pub const fn as_str(self) -> &'static str {
23 match self {
24 NoticeLevel::Debug => "DEBUG",
25 NoticeLevel::Log => "LOG",
26 NoticeLevel::Info => "INFO",
27 NoticeLevel::Notice => "NOTICE",
28 NoticeLevel::Warning => "WARNING",
29 }
30 }
31
32 /// The SQLSTATE of a notice whose report names none, as `errstart` assigns it: `01000` (`warning`) for a warning and `00000` (`successful_completion`) for every lower level.
33 pub const fn default_sqlstate(self) -> &'static str {
34 match self {
35 NoticeLevel::Warning => "01000",
36 NoticeLevel::Debug | NoticeLevel::Log | NoticeLevel::Info | NoticeLevel::Notice => {
37 "00000"
38 }
39 }
40 }
41}