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/// CONSTANTS
29///
30
31pub const MAX_INDEX_FIELDS: usize = 4;
32
33///
34/// ICYDB ACTOR PRELUDE
35/// using _ brings traits into scope and avoids name conflicts
36///
37
38pub mod prelude {
39    pub use crate::{
40        db,
41        db::{
42            executor::SaveExecutor,
43            primitives::{
44                self, FilterDsl, FilterExpr, FilterExt as _, LimitExpr, LimitExt as _, SortExpr,
45                SortExt as _,
46            },
47            query,
48            response::Response,
49        },
50        key::Key,
51        traits::{
52            CreateView as _, EntityKind as _, FilterView as _, Inner as _, Path as _,
53            UpdateView as _, View as _,
54        },
55        types::{Decimal, Ulid},
56        value::Value,
57        view::{Create, Filter, Update, View},
58    };
59    pub use candid::CandidType;
60    pub use serde::{Deserialize, Serialize};
61}
62
63///
64/// Third party re-exports
65///
66
67pub mod export {
68    pub use canic;
69    pub use ctor;
70    pub use derive_more;
71    pub use num_traits;
72    pub use remain;
73}
74
75use candid::CandidType;
76use serde::{Deserialize, Serialize};
77use thiserror::Error as ThisError;
78
79///
80/// Error
81///
82/// top level error should handle all sub-errors, but not expose the candid types
83/// as that would be a lot of them
84///
85
86#[derive(CandidType, Debug, Deserialize, Serialize, ThisError)]
87pub enum Error {
88    // third party
89    #[error("{0}")]
90    CanicError(String),
91
92    #[error("{0}")]
93    DbError(String),
94
95    #[error("{0}")]
96    InterfaceError(String),
97
98    #[error("{0}")]
99    SerializeError(String),
100
101    #[error("{0}")]
102    VisitorError(String),
103}
104
105macro_rules! from_to_string {
106    ($from:ty, $variant:ident) => {
107        impl From<$from> for Error {
108            fn from(e: $from) -> Self {
109                Error::$variant(e.to_string())
110            }
111        }
112    };
113}
114
115from_to_string!(canic::Error, CanicError);
116from_to_string!(db::DbError, DbError);
117from_to_string!(interface::InterfaceError, InterfaceError);
118from_to_string!(serialize::SerializeError, SerializeError);
119from_to_string!(visitor::VisitorError, VisitorError);