1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::{fmt::Debug, rc::Rc, sync::atomic::AtomicUsize};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum SqlBulderError {
#[error("`{0}`")]
MissingParts(String),
}
pub trait Sql {
fn sql(&self, s: String, ctx: &Context) -> String;
}
pub trait Id: Debug + Sql {
fn id(&self) -> usize;
}
pub type Result<T> = std::result::Result<T, SqlBulderError>;
#[derive(Debug)]
pub struct Context {}
impl Context {
pub fn new() -> Self {
Context {}
}
}
pub type Identifier = Rc<dyn Id>;
pub struct IdGen {}
impl IdGen {
pub fn id() -> usize {
static ID: AtomicUsize = AtomicUsize::new(0);
ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
}
}