Coder Social home page Coder Social logo

rust-pretty-sqlite's Introduction

pretty-sqlite - Simple, Minimalistic Pretty Prints for SQLite

This library assists 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.

NOTES:

  • Version 0.0.x will undergo API changes. Feel free to cherry-pick the code you want.
  • The upcoming version 0.1.x will be more stable but may still include some API-breaking changes. Thus, it is recommended to lock to a specific version (e.g., =0.1.2).
  • Version 0.2.x and onward will follow semantic versioning more strictly.

IMPORTANT: By default, all queries/prints are limited to 300 records. Using pretty_selection_with_options and the PrettyOptions can change this default behavior.

The API convention is as follows:

  • Functions prefixed with pretty_..., like pretty_table and pretty_select, return a formatted string of the table/query content.
  • Functions prefixed with print_..., like print_table and print_select, call println!() on the function above.

There is also a more advanced function:

  • pretty_select_with_options(conn, sql, params, pretty_options) allows customization of the table result with PrettyOptions.

Example:

let conn = Connection::open_in_memory()?; // for file: Connection::open(path)?
// ... seed db

// -- Print table
pretty_sqlite::print_table(&conn, "person")?;

// Same as:
// let content = pretty_sqlite::pretty_table(&conn, "person")?;
// println!("{content}");

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 = Connection::open_in_memory()?; // for file: Connection::open(path)?
// ... seed db

pretty_sqlite::print_select(&conn, "select id, name, yob from person where id > ?", (2,))?;

// 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 │
└────┴────────────┴──────┘

See examples/readme.rs

rust-pretty-sqlite's People

Contributors

jeremychone avatar

Stargazers

Mark Homoky avatar

Watchers

 avatar

Forkers

sanitu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.