Built insert and update builders
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
use std::{sync::OnceLock, time::Duration};
|
||||
|
||||
use std::{fmt, sync::OnceLock, time::Duration};
|
||||
use std::fmt::Display;
|
||||
use redis::{aio::MultiplexedConnection as RedisConnection, Client as RedisClient, RedisResult};
|
||||
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};
|
||||
use crate::error::SirenResult;
|
||||
|
||||
pub mod condition;
|
||||
pub mod events;
|
||||
pub mod guilds;
|
||||
pub mod insert;
|
||||
pub mod messages;
|
||||
pub mod query;
|
||||
pub mod update;
|
||||
|
||||
static POOL: OnceLock<Pool<Postgres>> = OnceLock::new();
|
||||
static REDIS: OnceLock<RedisClient> = OnceLock::new();
|
||||
@@ -84,3 +87,44 @@ async fn run_migrations() -> SirenResult<()> {
|
||||
sqlx::migrate!().run(pool).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Value {
|
||||
Int(i32),
|
||||
OptionalInt(Option<i32>),
|
||||
BigInt(i64),
|
||||
OptionalBigInt(Option<i64>),
|
||||
Float(f32),
|
||||
OptionalFloat(Option<f32>),
|
||||
Double(f64),
|
||||
OptionalDouble(Option<f64>),
|
||||
Bool(bool),
|
||||
OptionalBool(Option<bool>),
|
||||
Text(String),
|
||||
OptionalText(Option<String>),
|
||||
}
|
||||
|
||||
impl Display for Value {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Value::Int(n) => write!(f, "{}", n),
|
||||
Value::OptionalInt(Some(n)) => write!(f, "{}", n),
|
||||
Value::OptionalInt(None) => write!(f, "NULL"),
|
||||
Value::BigInt(n) => write!(f, "{}", n),
|
||||
Value::OptionalBigInt(Some(n)) => write!(f, "{}", n),
|
||||
Value::OptionalBigInt(None) => write!(f, "NULL"),
|
||||
Value::Float(n) => write!(f, "{}", n),
|
||||
Value::OptionalFloat(Some(n)) => write!(f, "{}", n),
|
||||
Value::OptionalFloat(None) => write!(f, "NULL"),
|
||||
Value::Double(n) => write!(f, "{}", n),
|
||||
Value::OptionalDouble(Some(n)) => write!(f, "{}", n),
|
||||
Value::OptionalDouble(None) => write!(f, "NULL"),
|
||||
Value::Bool(n) => write!(f, "{}", n),
|
||||
Value::OptionalBool(Some(n)) => write!(f, "{}", n),
|
||||
Value::OptionalBool(None) => write!(f, "NULL"),
|
||||
Value::Text(s) => write!(f, "'{}'", s.replace("'", "''")),
|
||||
Value::OptionalText(Some(s)) => write!(f, "'{}'", s.replace("'", "''")),
|
||||
Value::OptionalText(None) => write!(f, "NULL"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user