pub struct Tokenizer { /* private fields */ }Expand description
Splits SQL into Tokens, the way one dialect writes it.
Dialects differ in the identifier quote (a backtick, or a double quote
for PostgreSQL and SQLite), in MySQL’s # line comments and in
PostgreSQL’s multi-character operators (@>, <@, <=>, <->, <#>,
?|, ?&).
PHP: Utopia\Query\Tokenizer\Tokenizer and its dialect subclasses.
Implementations§
Source§impl Tokenizer
impl Tokenizer
Sourcepub const fn new() -> Self
pub const fn new() -> Self
The standard tokenizer: identifiers quoted with backticks (or double quotes).
PHP: new Tokenizer\Tokenizer().
Sourcepub const fn postgresql() -> Self
pub const fn postgresql() -> Self
PostgreSQL: identifiers quoted with double quotes, and its multi-character operators as one token.
PHP: new Tokenizer\PostgreSQL().
Sourcepub const fn sqlite() -> Self
pub const fn sqlite() -> Self
SQLite: a backslash is a character like any other.
PHP: new Tokenizer\SQLite().
Sourcepub const fn clickhouse() -> Self
pub const fn clickhouse() -> Self
ClickHouse: as the standard tokenizer.
PHP: new Tokenizer\ClickHouse().
Sourcepub const fn with_literal(self, literal: StringLiteral) -> Self
pub const fn with_literal(self, literal: StringLiteral) -> Self
The tokenizer reading string literals by literal’s rules.
PHP: new Tokenizer($literal).
Sourcepub fn tokenize<'a, S: AsRef<[u8]> + ?Sized>(
&self,
sql: &'a S,
) -> Result<Vec<Token<'a>>>
pub fn tokenize<'a, S: AsRef<[u8]> + ?Sized>( &self, sql: &'a S, ) -> Result<Vec<Token<'a>>>
The tokens of sql, whitespace and comments included, ending with an
TokenType::Eof token. Fails with Error::Validation on an
unterminated string literal or quoted identifier.
PHP: Tokenizer::tokenize().
use utopia_query::tokenizer::{TokenType, Tokenizer};
let tokens = Tokenizer::mysql().tokenize("SELECT 1 #note")?;
assert_eq!(tokens[4].kind, TokenType::LineComment);
assert_eq!(tokens[4].text(), "-- note");
assert!(Tokenizer::new().tokenize("SELECT 'open").is_err());use Utopia\Query\Tokenizer\MySQL;
$tokens = (new MySQL())->tokenize('SELECT 1 #note');
echo $tokens[4]->type->name, ' ', $tokens[4]->value, "\n"; // LineComment -- noteTrait Implementations§
impl Copy for Tokenizer
impl Eq for Tokenizer
impl StructuralPartialEq for Tokenizer
Auto Trait Implementations§
impl Forget for Tokenizer
impl Freeze for Tokenizer
impl Move for Tokenizer
impl RefUnwindSafe for Tokenizer
impl Send for Tokenizer
impl Sync for Tokenizer
impl Unpin for Tokenizer
impl UnsafeUnpin for Tokenizer
impl UnwindSafe for Tokenizer
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.