pub struct SqlBuilder<'config> { /* private fields */ }Expand description
AST builder for SQL.
This builder is responsible for converting the generic syntax tree (green/red trees)
into a strongly-typed SQL Abstract Syntax Tree (AST). It implements the Builder
trait, allowing it to be used within the Oak incremental parsing framework.
§Usage
use oak_core::{Builder, source::SourceText};
use oak_sql::{SqlBuilder, SqlLanguage};
let config = SqlLanguage::default();
let builder = SqlBuilder::new(&config);
// ... use builder to build AST from sourceImplementations§
Source§impl<'config> SqlBuilder<'config>
impl<'config> SqlBuilder<'config>
Sourcepub fn new(config: &'config SqlLanguage) -> Self
pub fn new(config: &'config SqlLanguage) -> Self
Creates a new SqlBuilder with the specified language configuration.
Trait Implementations§
Source§impl<'config> Builder<SqlLanguage> for SqlBuilder<'config>
impl<'config> Builder<SqlLanguage> for SqlBuilder<'config>
Source§fn build<'a, S: Source + ?Sized>(
&self,
source: &S,
edits: &[TextEdit],
cache: &'a mut impl BuilderCache<SqlLanguage>,
) -> BuildOutput<SqlLanguage>
fn build<'a, S: Source + ?Sized>( &self, source: &S, edits: &[TextEdit], cache: &'a mut impl BuilderCache<SqlLanguage>, ) -> BuildOutput<SqlLanguage>
Builds the SQL AST from the source text and edits.
This is the main entry point for the builder. It performs the following steps:
- Initializes a
SqlParserwith the current configuration. - Executes the parser to produce a
RedTree(Concrete Syntax Tree). - Converts the resulting green tree into a typed
SqlRootAST. - Handles incremental updates by passing
editsto the parser.
§Examples
use oak_core::{Builder, ParseSession, source::SourceText};
use oak_sql::{SqlBuilder, SqlLanguage};
let config = SqlLanguage::default();
let builder = SqlBuilder::new(&config);
let mut cache = ParseSession::default();
let source = "SELECT * FROM users";
let output = builder.build(&source, &[], &mut cache);
if let Ok(root) = output.result {
assert_eq!(root.statements.len(), 1);
}§Errors
Returns an error if parsing fails or if the CST cannot be lowered to a valid AST.
Source§impl<'config> Clone for SqlBuilder<'config>
impl<'config> Clone for SqlBuilder<'config>
Source§fn clone(&self) -> SqlBuilder<'config>
fn clone(&self) -> SqlBuilder<'config>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<'config> Freeze for SqlBuilder<'config>
impl<'config> RefUnwindSafe for SqlBuilder<'config>
impl<'config> Send for SqlBuilder<'config>
impl<'config> Sync for SqlBuilder<'config>
impl<'config> Unpin for SqlBuilder<'config>
impl<'config> UnsafeUnpin for SqlBuilder<'config>
impl<'config> UnwindSafe for SqlBuilder<'config>
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
Mutably borrows from an owned value. Read more