pretty-sqlite - Simple, Minimalistic Pretty Printing for SQLite
IMPORTANT See Cargo.toml to see which version of rusqlite should be used with this crate.
This library helps with testing and exploratory development of SQLite by conveniently printing the contents of a table or a select statement into a nicely formatted table using the tabled crate.
This library is based on the rusqlite crate.
IMPORTANT: By default, all queries/prints are limited to 300 records. Using the pretty_... functions with a PrettyOptions argument can change this default behavior.
The API convention is as follows:
- Functions prefixed with
pretty_..., likepretty_tableandpretty_select, return a formatted string of the table or query content. - Functions prefixed with
print_..., likeprint_tableandprint_select, callprintln!()on the correspondingpretty_...function.
There is also a more advanced function:
pretty_select_with_options(conn, sql, params, pretty_options)allows customization of the table output withPrettyOptions.
Example:
let conn = open_in_memory?; // For a file: Connection::open(path)?
// ... seed db
// -- Print table
print_table?;
// Same as:
// let content = pretty_sqlite::pretty_table(&conn, "person")?;
// println!("{content}");
This will print something like:
TABLE: person
┌────┬────────────┬──────┬──────────┬───────────────────┐
│ id │ name │ yob │ data_t │ data_b │
├────┼────────────┼──────┼──────────┼───────────────────┤
│ 1 │ "Person 1" │ 1951 │ "Data 1" │ BLOB (length: 10) │
├────┼────────────┼──────┼──────────┼───────────────────┤
│ 2 │ "Person 2" │ 1952 │ "Data 2" │ BLOB (length: 10) │
├────┼────────────┼──────┼──────────┼───────────────────┤
│ 3 │ "Person 3" │ 1953 │ "Data 3" │ BLOB (length: 10) │
├────┼────────────┼──────┼──────────┼───────────────────┤
│ 4 │ "Person 4" │ 1954 │ "Data 4" │ BLOB (length: 10) │
├────┼────────────┼──────┼──────────┼───────────────────┤
│ 5 │ "Person 5" │ 1955 │ "Data 5" │ BLOB (length: 10) │
└────┴────────────┴──────┴──────────┴───────────────────┘
let conn = open_in_memory?; // For a file: Connection::open(path)?
// ... seed db
print_select?;
// Same as:
// let content = pretty_sqlite::pretty_select(&conn, "select id, name, yob from person where id > ?", (2,))?;
// println!("{content}");
┌────┬────────────┬──────┐
│ id │ name │ yob │
├────┼────────────┼──────┤
│ 3 │ "Person 3" │ 1953 │
├────┼────────────┼──────┤
│ 4 │ "Person 4" │ 1954 │
├────┼────────────┼──────┤
│ 5 │ "Person 5" │ 1955 │
└────┴────────────┴──────┘