#![allow(clippy::await_holding_refcell_ref)]
#![warn(anonymous_parameters, bad_style, missing_docs)]
#![warn(unused, unused_extern_crates, unused_import_braces, unused_qualifications)]
#![warn(unsafe_code)]
use std::sync::Arc;
mod clocks;
pub(crate) mod logger;
use crate::logger::LogEntry;
pub use logger::{init, Handle};
#[cfg(test)]
mod testutils;
#[cfg(not(any(feature = "postgres", feature = "sqlite")))]
compile_error!("one of the features ['postgres', 'sqlite'] must be enabled");
#[cfg(feature = "postgres")]
pub mod postgres;
#[cfg(feature = "sqlite")]
pub mod sqlite;
#[derive(Clone)]
pub struct Connection(Arc<dyn Db + Send + Sync + 'static>);
impl Connection {
pub async fn create_schema(&self) -> Result<()> {
self.0.create_schema().await
}
}
pub(crate) type Result<T> = std::result::Result<T, String>;
#[async_trait::async_trait]
pub(crate) trait Db {
async fn create_schema(&self) -> Result<()>;
async fn get_log_entries(&self) -> Result<Vec<String>>;
async fn put_log_entries(&self, entries: Vec<LogEntry<'_, '_>>) -> Result<()>;
}
fn truncate_option_str(input: Option<&str>, max_len: usize) -> Option<String> {
match input {
Some(s) => {
let mut s = s.to_owned();
s.truncate(max_len);
Some(s)
}
None => None,
}
}