mod macros;
mod rules;
mod traits;
pub use macros::*;
pub use traits::*;
pub use sqlx;
pub mod derive {
pub use super::Table;
pub use super::Delete;
pub use super::DeleteImpl;
pub use super::Insert;
pub use super::InsertImpl;
pub use super::Select;
pub use super::SelectImpl;
pub use super::Update;
pub use super::UpdateImpl;
}
pub mod docs {
#[allow(unused_imports)]
use super::*;
#[doc = include_str!("docs/documentation.md")]
pub mod attr {
#[allow(unused_imports)]
use super::*;
#[doc = include_str!("docs/notation.md")]
pub mod note {}
}
}
#[doc(hidden)]
pub mod require {
use super::*;
pub const fn table<T: Table>() {}
pub const fn delete<T: DeleteImpl>() {}
pub const fn insert<T: InsertImpl>() {}
pub const fn select<T: SelectImpl>() {}
pub const fn update<T: UpdateImpl>() {}
}
#[cfg(feature = "serde")]
pub mod double_option {
pub fn deserialize<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
where
T: serde::Deserialize<'de>,
D: serde::Deserializer<'de>,
{
serde::Deserialize::deserialize(deserializer).map(Some)
}
pub fn serialize<T, S>(value: &Option<T>, serializer: S) -> Result<S::Ok, S::Error>
where
T: serde::Serialize,
S: serde::Serializer,
{
match value {
None => serializer.serialize_unit(),
Some(v) => v.serialize(serializer),
}
}
}
#[doc(hidden)]
pub mod dynamic {
pub struct Bind<T> {
pub value: T,
pub index: Option<usize>,
}
impl<T> Bind<T> {
pub fn new(value: T) -> Self {
Self { value, index: None }
}
pub fn bind<'q, A>(&mut self, args: &mut Result<A, sqlx::error::BoxDynError>) -> usize
where
T: 'q + sqlx::Encode<'q, A::Database> + sqlx::Type<A::Database> + Copy,
A: sqlx::Arguments<'q>,
{
*self.index.get_or_insert_with(|| {
if let Ok(ok) = args {
if let Err(err) = ok.add(self.value) {
*args = Err(err);
}
}
args.as_ref().map_or(0, |args| args.len())
})
}
}
pub trait Rip {
type Rip;
fn rip(&self) -> Self::Rip;
}
impl<T> Rip for Option<T> {
type Rip = T;
fn rip(&self) -> Self::Rip {
panic!("not possible")
}
}
}
#[doc(hidden)]
pub mod spec_error {
#[doc(hidden)]
#[macro_export]
macro_rules! __spec_error {
($e:expr) => {{
use $crate::spec_error::SpecError as _;
let wrapper = $crate::spec_error::SpecErrorWrapper($e);
(&&&&wrapper).__sqly_spec_error()(wrapper.0)
}};
}
pub struct SpecErrorWrapper<E>(pub E);
pub trait SpecError<E> {
fn __sqly_spec_error(&self) -> fn(E) -> sqlx::error::BoxDynError;
}
impl<E: std::error::Error + Send + Sync + 'static> SpecError<E> for &&&SpecErrorWrapper<E> {
fn __sqly_spec_error(&self) -> fn(E) -> sqlx::error::BoxDynError {
|e| Box::new(e)
}
}
impl<E: std::fmt::Display> SpecError<E> for &&SpecErrorWrapper<E> {
fn __sqly_spec_error(&self) -> fn(E) -> sqlx::error::BoxDynError {
|e| e.to_string().into()
}
}
impl<E: std::fmt::Debug> SpecError<E> for &SpecErrorWrapper<E> {
fn __sqly_spec_error(&self) -> fn(E) -> sqlx::error::BoxDynError {
|e| format!("{:?}", e).into()
}
}
impl<E> SpecError<E> for SpecErrorWrapper<E> {
fn __sqly_spec_error(&self) -> fn(E) -> sqlx::error::BoxDynError {
|_| format!("unprintable error: {}", std::any::type_name::<E>()).into()
}
}
#[test]
fn spec_error() {
type E = sqlx::error::BoxDynError;
let e: E = __spec_error!(std::io::Error::from(std::io::ErrorKind::Other));
assert_eq!(format!("{:?}", e), "Kind(Other)");
assert_eq!(format!("{}", e), "other error");
let e: E = __spec_error!("display");
assert_eq!(format!("{:?}", e), "\"display\"");
let e: E = __spec_error!(&["debug"]);
assert_eq!(format!("{}", e), "[\"debug\"]");
let _: E = __spec_error!(SpecErrorWrapper(&e));
}
}