Skip to main content

surql_parser/upstream/sql/
param.rs

1use crate::upstream::fmt::EscapeKwFreeIdent;
2use surrealdb_types::{SqlFormat, ToSql, write_sql};
3#[derive(Clone, Debug, Default, PartialEq, Eq)]
4#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
5pub struct Param(String);
6impl Param {
7	/// Create a new identifier
8	///
9	/// This function checks if the string has a null byte, returns None if it
10	/// has.
11	pub fn new(str: String) -> Self {
12		Self(str)
13	}
14	pub fn into_string(self) -> String {
15		self.0
16	}
17}
18impl ToSql for Param {
19	fn fmt_sql(&self, f: &mut String, fmt: SqlFormat) {
20		write_sql!(f, fmt, "${}", EscapeKwFreeIdent(&self.0))
21	}
22}