icydb_core/
lib.rs

1//
2// icydb-core
3//
4// [for external use only, keep out of reach of children]
5//
6pub mod db;
7pub mod design;
8pub mod hash;
9pub mod index;
10pub mod interface;
11pub mod key;
12pub mod macros;
13pub mod obs;
14pub mod serialize;
15pub mod traits;
16pub mod types;
17pub mod value;
18pub mod view;
19pub mod visitor;
20
21pub use index::IndexSpec;
22pub use key::Key;
23pub use serialize::{deserialize, serialize};
24pub use value::Value;
25pub use visitor::{sanitize, validate};
26
27///
28/// CRATE
29///
30
31pub const VERSION: &str = env!("CARGO_PKG_VERSION");
32
33///
34/// CONSTANTS
35///
36
37pub const MAX_INDEX_FIELDS: usize = 4;
38
39///
40/// ICYDB ACTOR PRELUDE
41/// using _ brings traits into scope and avoids name conflicts
42///
43
44pub mod prelude {
45    pub use crate::{
46        db,
47        db::{
48            executor::SaveExecutor,
49            primitives::{
50                self, FilterDsl, FilterExpr, FilterExt as _, LimitExpr, LimitExt as _, SortExpr,
51                SortExt as _,
52            },
53            query,
54            response::Response,
55        },
56        key::Key,
57        traits::{
58            CreateView as _, EntityKind as _, FilterView as _, Inner as _, Path as _,
59            UpdateView as _, View as _,
60        },
61        types::{Decimal, Ulid},
62        value::Value,
63        view::{Create, Filter, Update, View},
64    };
65    pub use candid::CandidType;
66    pub use serde::{Deserialize, Serialize};
67}
68
69///
70/// Third party re-exports
71///
72
73pub mod export {
74    pub use canic;
75    pub use ctor;
76    pub use derive_more;
77    pub use num_traits;
78    pub use remain;
79}
80
81use candid::CandidType;
82use serde::{Deserialize, Serialize};
83use thiserror::Error as ThisError;
84
85///
86/// Error
87///
88/// top level error should handle all sub-errors, but not expose the candid types
89/// as that would be a lot of them
90///
91
92#[derive(CandidType, Debug, Deserialize, Serialize, ThisError)]
93pub enum Error {
94    // third party
95    #[error("{0}")]
96    CanicError(String),
97
98    #[error("{0}")]
99    DbError(String),
100
101    #[error("{0}")]
102    InterfaceError(String),
103
104    #[error("{0}")]
105    SerializeError(String),
106
107    #[error("{0}")]
108    VisitorError(String),
109}
110
111macro_rules! from_to_string {
112    ($from:ty, $variant:ident) => {
113        impl From<$from> for Error {
114            fn from(e: $from) -> Self {
115                Error::$variant(e.to_string())
116            }
117        }
118    };
119}
120
121from_to_string!(canic::Error, CanicError);
122from_to_string!(db::DbError, DbError);
123from_to_string!(interface::InterfaceError, InterfaceError);
124from_to_string!(serialize::SerializeError, SerializeError);
125from_to_string!(visitor::VisitorError, VisitorError);