#postgresql #run #user #temporary #port #db

app pgdb_cli

Command-line application to run a Postgres database

3 releases (breaking)

0.3.0 Apr 9, 2024
0.2.0 Apr 1, 2024
0.1.2 Jun 15, 2021

#474 in Database interfaces

Download history 7/week @ 2024-02-22 7/week @ 2024-02-29 147/week @ 2024-03-28 140/week @ 2024-04-04 25/week @ 2024-04-11

312 downloads per month

MIT/Apache

25KB
445 lines

pgdb-rs

A small rust crate that allow easy creation and running of temporary Postgres databases, typically used for unit tests or similar things:

let user = "dev";
let pw = "devpw";
let db = "dev";

// Run a postgres instance on port `15432`.
let pg = pgdb::Postgres::build()
    .start()
    .expect("could not build postgres database");

// We can now create a regular user and a database.
pg.as_superuser()
  .create_user(user, pw)
  .expect("could not create normal user");

pg.as_superuser()
  .create_database(db, user)
  .expect("could not create normal user's db");

// Now we can run DDL commands, e.g. creating a table.
let client = pg.as_user(user, pw);
client
    .run_sql(db, "CREATE TABLE foo (id INT PRIMARY KEY);")
    .expect("could not run table creation command");

See the documentation for details.

Dependencies

~6–16MB
~200K SLoC