use surrealdb_strand::Strand;
use surrealdb_types::{SqlFormat, ToSql, write_sql};
use crate::fmt::EscapeKwFreeIdent;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct Param(Strand);
impl Param {
pub fn new(str: impl Into<Strand>) -> Self {
Self(str.into())
}
pub fn as_str(&self) -> &str {
self.0.as_str()
}
pub fn into_string(self) -> String {
self.0.into_string()
}
pub fn into_strand(self) -> Strand {
self.0
}
}
impl ToSql for Param {
fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
write_sql!(f, fmt, "${}", EscapeKwFreeIdent(self.as_str()))
}
}
impl From<Param> for crate::expr::Param {
fn from(v: Param) -> Self {
crate::expr::Param::from(v.0)
}
}
impl From<crate::expr::Param> for Param {
fn from(v: crate::expr::Param) -> Self {
Self(v.into_strand())
}
}