[][src]Struct postgres_parser::SqlStatementScanner

pub struct SqlStatementScanner<'a> { /* fields omitted */ }

The SqlStatementScanner allows for scanning a blob of SQL statements and ultimately iterating over each statement, one at a time, producing a ScannedStatement that includes the raw SQL, that SQL's parsetree, and optional "COPY ... FROM stdin;" payload data.

When parsing multiple SQL statements, the SqlStatementScanner is superior to directly calling parse_query() as each individual statement is parsed on its own. This provides for syntax checking each statement individually, instead of failing if any statement is syntactically incorrect.

Statement Scanning Notes

  • Trailing whitespace after a statement end ("SELECT 1; \n\n SELECT 2;") are included with the preceding statement. As such, this would scan into two statements: ["SELECT 1; \n\n ", "SELECT 2;"]
  • Statement-terminating semicolons are included with the statement
  • The final statement need not have a terminating semicolon

Examples

Parsing multiple statements:

use postgres_parser::SqlStatementScanner;
let scanner = SqlStatementScanner::new("SELECT 0; SELECT 1; SELECT 2;");
for (idx, statement) in scanner.iter().enumerate() {
    assert_eq!(statement.sql.trim_end(), &format!("SELECT {};", idx));
}

Implementations

impl<'a> SqlStatementScanner<'a>[src]

pub fn new(sql: &'a str) -> Self[src]

pub fn iter(&self) -> SqlStatementScannerIterator[src]

Trait Implementations

impl<'a> IntoIterator for SqlStatementScanner<'a>[src]

type Item = ScannedStatement<'a>

The type of the elements being iterated over.

type IntoIter = SqlStatementScannerIterator<'a>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<'a> RefUnwindSafe for SqlStatementScanner<'a>

impl<'a> Send for SqlStatementScanner<'a>

impl<'a> Sync for SqlStatementScanner<'a>

impl<'a> Unpin for SqlStatementScanner<'a>

impl<'a> UnwindSafe for SqlStatementScanner<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.