This crate will make it easy to parse a SQLite database. This can be useful for code generation.
Add a dependency on this crate by adding this line under [dependencies]
in your Cargo.toml
file:
sqlite_parser = "*"
Than implement the Parser
trait and call the parse
function with the implementing
struct
and the location of the SQLite file. There is a convenience method that doesn't require an implementing Parser
trait
called parse_no_parser
.
There are 2 ways of using this library
- Implement the Parser
trait and call the parse
function.
```
use sqliteparser::{parse, Parser, Table};
use std::fs::File;
use std::collections::hashmap::RandomState;
use std::collections::HashMap;
/// This is the location to the SQLite file let mysqlitefilelocation = std::env::currentdir().unwrap().join("test_sqlite.sqlite3");
/// Create a parse struct to process the tables
/// Note: there is a convenience method parse_no_parser
that doesn't require a parser.
struct Parse;
impl Parser for Parse {
fn process_tables(&mut self, tables: HashMap
/// Start the parsing parse(&mysqlitefile_location, &mut Parse { }); ```
Parser
trait and call the parse_no_parser
function.
```
use sqliteparser::parsenoparser;
use std::fs::File;
/// This is the location to the SQLite file
let mysqlitefilelocation = std::env::currentdir().unwrap().join("testsqlite.sqlite3");/// Start the parsing let tables = parsenoparser(&mysqlitefile_location); /// Do stuff with the tables property! ```