Command-line tool to make Rust source code entities from Postgres tables.

Overview

pg2rs

Command-line tool to make Rust source code entities from Postgres tables. Generates:

  • enums
  • structs

which can be then used like

mod structs;
use structs::{User};

let result = client.query("SELECT * FROM \"Users\"", &[]).await.unwrap();
let users: Vec<User> = result.into_iter().map(|row| User::from(row)).collect();
println!("{:#?}", users);

It is not an ORM, main purpose is to have tables DDL as a source of truth. DDL can be generated using some tool like Alembic, and then pg2rs is used to reflect changes in your structs.rs

Usage

$ pg2rs --help
pg2rs 0.0.2
Stanislav Panasik <[email protected]>
Make Rust entities from PostgreSQL schema

USAGE:
    pg2rs [OPTIONS] --schema <schema>

OPTIONS:
    -c, --connection-string <connection-string>
            full connection string instead of separate credentials in a form
            postgresql://username:password@host:port/dbname [env: POSTGRES_CONNECTION_STRING=]

    -d, --database <database>
            [env: POSTGRES_DATABASE=]

    -h, --host <host>
            [env: POSTGRES_HOST=]

        --help
            Print help information

    -m, --use-rust-decimal
            use chrono DateTime for timestamps [env: USE_RUST_DECIMAL=]

    -n, --use-chrono-crate
            use chrono DateTime for timestamps [env: USE_CHRONO_CRATE=]

    -o, --output_file <output_file>
            output file path [env: OUTPUT_FILE=]

    -p, --password <password>
            [env: POSTGRES_PASSWORD=]

    -r, --port <port>
            [env: POSTGRES_PORT=]

    -s, --schema <schema>
            [env: POSTGRES_SCHEMA=]

    -t, --table <table>
            [env: POSTGRES_TABLE=]

    -u, --user <user>
            [env: POSTGRES_USER=]

    -V, --version
            Print version information

    -w, --postgres_crate <postgres_crate>
            Postgres crate [env: POSTGRES_CRATE=] [default: postgres] [possible values: postgres,
            sqlx, tokio_postgres]

    -z, --singularize-table-names
            [env: SINGULARIZE_TABLE_NAMES=]

Roadmap

  • Add unit tests

Authors

License

MIT

You might also like...
postgres-ical - a PostgreSQL extension that adds features related to parsing RFC-5545 « iCalendar » data from within a PostgreSQL database

postgres-ical - a PostgreSQL extension that adds features related to parsing RFC-5545 « iCalendar » data from within a PostgreSQL database

The simplest implementation of LLM-backed vector search on Postgres.

pg_vectorize under development The simplest implementation of LLM-backed vector search on Postgres. -- initialize an existing table select vectorize.i

Postgres Foreign Data Wrapper for Clerk.com API

Pre-requisites Postgres-15 Rust pgrx Getting Started To run the program locally, clone the repository git clone https://github.com/tembo-io/clerk_fdw.

A command-line tool for DatPiff Mixtapes
A command-line tool for DatPiff Mixtapes

DatPiff CLI DatPiff CLI helps you browse DatPiff mixtapes right from the terminal. Installation Simply run: $ cargo install datpiff macOS/Linux $ brew

Command-line tool to convert Apple HealthKit data to a SQLite database.

healthkit-to-sqlite Command-line tool to convert Apple HealthKit data to a SQLite database. Getting Started Open the Health app on your iOS device. Cl

⚡🦀 🧨 make your rust types fit DynamoDB and visa versa

🦀 🧨 dynomite dynomite makes DynamoDB fit your types (and visa versa) Overview Goals ⚡ make writing dynamodb applications in rust a productive experi

A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy
A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy

A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy

Thin wrapper around [`tokio::process`] to make it streamable

process-stream Wraps tokio::process::Command to future::stream. Install process-stream = "0.2.2" Example usage: From VecString or Vec&str use proc

Make a DAO Drop!

DAO drop tool This tool parses a Cosmos SDK chain export JSON file, to produce a CSV list of addresses and amounts. It can handle extremely large file

Releases(0.0.2)
Owner
Stanislav
Stanislav
An easy-to-use, zero-downtime schema migration tool for Postgres

Reshape is an easy-to-use, zero-downtime schema migration tool for Postgres. It automatically handles complex migrations that would normally require downtime or manual multi-step changes.

Fabian Lindfors 1.4k Dec 25, 2022
XLite - query Excel (.xlsx, .xls) and Open Document spreadsheets (.ods) as SQLite virtual tables

XLite - query Excel (.xlsx, .xls) and Open Document spreadsheets (.ods) as SQLite virtual tables XLite is a SQLite extension written in Rust. The main

Sergey Khabibullin 1.1k Dec 28, 2022
Manage Redshift/Postgres privileges in GitOps style written in Rust

grant-rs An open-source project that aims to manage Postgres/Redshift database roles and privileges in GitOps style, written in Rust. Home | Documenta

Duyet Le 13 Nov 23, 2022
cogo rust coroutine database driver (Mysql,Postgres,Sqlite)

cdbc Coroutine Database driver Connectivity.based on cogo High concurrency,based on coroutine No Future<'q,Output=*>,No async fn, No .await , no Poll*

co-rs 10 Nov 13, 2022
rust-postgres support library for the r2d2 connection pool

r2d2-postgres Documentation rust-postgres support library for the r2d2 connection pool. Example use std::thread; use r2d2_postgres::{postgres::NoTls,

Steven Fackler 128 Dec 26, 2022
A Rust application that inserts Discogs data dumps into Postgres

Discogs-load A Rust application that inserts Discogs data dumps into Postgres. Discogs-load uses a simple state machine with the quick-xml Rust librar

Dylan 7 Dec 9, 2022
A Pub/Sub library for Rust backed by Postgres

Unisub Unisub is a Pub/Sub library for Rust, using Postgres as the backend. It offers a convenient way to publish and subscribe to messages across dif

Nick Rempel 12 Oct 6, 2023
Rust library and daemon for easily starting postgres databases per-test without Docker

pgtemp pgtemp is a Rust library and cli tool that allows you to easily create temporary PostgreSQL servers for testing without using Docker. The pgtem

Harry Stern 165 Mar 22, 2024
Making Postgres and Elasticsearch work together like it's 2021

Making Postgres and Elasticsearch work together like it's 2021 Readme ZomboDB brings powerful text-search and analytics features to Postgres by using

ZomboDB 4.2k Jan 2, 2023
Distributed, version controlled, SQL database with cryptographically verifiable storage, queries and results. Think git for postgres.

SDB - SignatureDB Distributed, version controlled, SQL database with cryptographically verifiable storage, queries and results. Think git for postgres

Fremantle Industries 5 Apr 26, 2022