pub struct Serializer { /* private fields */ }Expand description
Writes a syntax tree as SQL, quoting identifiers the way one dialect does: backticks (MySQL, MariaDB, ClickHouse, and the base serializer) or double quotes (PostgreSQL, SQLite), with the quote doubled inside.
PHP: Utopia\Query\AST\Serializer and its dialect subclasses.
use utopia_query::ast::{Parser, Serializer};
let select = Parser::new().parse_sql("select id, name from users where id = 1")?;
assert_eq!(Serializer::new().serialize(&select)?, "SELECT `id`, `name` FROM `users` WHERE `id` = 1");
assert_eq!(Serializer::postgresql().serialize(&select)?, r#"SELECT "id", "name" FROM "users" WHERE "id" = 1"#);use Utopia\Query\AST\Parser;
use Utopia\Query\AST\Serializer;
use Utopia\Query\Tokenizer\Tokenizer;
$select = (new Parser())->parse(Tokenizer::filter((new Tokenizer())->tokenize('select id, name from users where id = 1')));
echo (new Serializer())->serialize($select), "\n"; // SELECT `id`, `name` FROM `users` WHERE `id` = 1Implementations§
Source§impl Serializer
impl Serializer
Sourcepub const fn new() -> Self
pub const fn new() -> Self
The base serializer: identifiers in backticks.
PHP: new Serializer().
Sourcepub const fn mariadb() -> Self
pub const fn mariadb() -> Self
MariaDB: identifiers in backticks.
PHP: new Serializer\MariaDB().
Sourcepub const fn clickhouse() -> Self
pub const fn clickhouse() -> Self
ClickHouse: identifiers in backticks.
PHP: new Serializer\ClickHouse().
Sourcepub const fn postgresql() -> Self
pub const fn postgresql() -> Self
PostgreSQL: identifiers in double quotes.
PHP: new Serializer\PostgreSQL().
Sourcepub const fn sqlite() -> Self
pub const fn sqlite() -> Self
SQLite: identifiers in double quotes.
PHP: new Serializer\SQLite().
Sourcepub const fn with_literal(self, literal: StringLiteral) -> Self
pub const fn with_literal(self, literal: StringLiteral) -> Self
The serializer writing string literals by literal’s rules.
PHP: new Serializer($literal).
Sourcepub const fn with_quote(quote: char) -> Self
pub const fn with_quote(quote: char) -> Self
A serializer quoting identifiers with quote (doubled inside them).
PHP: a subclass overriding quoteIdentifier().
Sourcepub fn serialize(&self, statement: &Select) -> Result<String>
pub fn serialize(&self, statement: &Select) -> Result<String>
statement as SQL. Fails with Error::Query on a node no SQL
position takes (a CaseWhen outside a CASE).
PHP: Serializer::serialize().
Sourcepub fn serialize_expression(&self, expression: &Expression) -> Result<String>
pub fn serialize_expression(&self, expression: &Expression) -> Result<String>
expression as SQL.
PHP: Serializer::serializeExpression().
Sourcepub fn quote_identifier(&self, name: &str) -> String
pub fn quote_identifier(&self, name: &str) -> String
name quoted as an identifier.
PHP: Serializer::quoteIdentifier() (protected).
Trait Implementations§
Source§impl AstWriter for Serializer
impl AstWriter for Serializer
Source§impl Clone for Serializer
impl Clone for Serializer
impl Copy for Serializer
Source§impl Debug for Serializer
impl Debug for Serializer
impl Eq for Serializer
Source§impl PartialEq for Serializer
impl PartialEq for Serializer
impl StructuralPartialEq for Serializer
Auto Trait Implementations§
impl Forget for Serializer
impl Freeze for Serializer
impl Move for Serializer
impl RefUnwindSafe for Serializer
impl Send for Serializer
impl Sync for Serializer
impl Unpin for Serializer
impl UnsafeUnpin for Serializer
impl UnwindSafe for Serializer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.