Skip to main content

parse

Function parse 

Source
pub fn parse(sql: &str) -> Result<ParsedStatement, SqlError>
Expand description

Parses one SQL statement.

The statement may end with a single ;. Keywords are case-insensitive and identifiers are case-sensitive. Names are not checked against a schema: that happens when the statement is executed.

§Errors

  • SqlError::Parse when sql is not a single statement of the supported grammar. The error carries the 1-based line and column of the offending token.
  • SqlError::MissingWhereClause when an UPDATE or DELETE has no WHERE clause.

§Examples

use wasm_dbms_sql::ast::Statement;

let parsed = wasm_dbms_sql::parse("DELETE FROM users WHERE id = ?")?;
assert!(matches!(parsed.statement, Statement::Delete(_)));
assert_eq!(parsed.parameter_count, 1);