This is a full implementation of an Apache Cassandra CQL3 query language parser. The goal of this package is to parse CQL3 statements into a structure that can be used in a multi-threaded envrionment. It uses the tree-sitter-cql3 parser to parse the original query and then constructs an editable thread safe representation of the query.
```rust use crate::cassandraast::CassandraAST; use crate::cassandrastatement::CassandraStatement; use crate::select::{Named, SelectElement};
let ast = CassandraAST::new("select foo from myTable" ); // verify that there was no error assert!( !ast.haserror() ); // get the parsed statement let stmt : CassandraStatement = ast.statement; match stmt { CassandraStatement::Select(select) => { select.columns.push( SelectElement::Column( Named { name : "bar".asstring(), alias : Some( "baz".asstring() ), })); select.orderclause = Some( OrderClause { name : "baz".asstring() } ); }, _ => {} } let editedstmt = stmt.to_string(); ```
The above code changes SELECT foo FROM myTable
to Select foo, bar AS baz FROM myTable ORDER BY baz ASC
.
_NOTE_: It is possible to create invalid statements. If in doubt reparse the new statement to verify that it is syntactically correct.
cassandra_ast
module.cassandra_statements
module.create_table
has the Create Table specific structs).common
module.Drop
statements have the same structure, it is in common_drop
.Create Role
) utilize the role_common
module.