atanmarko / rust-diesel-examples

Rust Diesel PostgreSQL examples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rust-diesel-examples

Rust Diesel PostgreSQL examples

When I used Diesel with PostgreSQL for the first time, I faced with the lack of complete working code examples. Here I have tried to assemble some convenient example use-cases in one place.

Setup

Install diesel cli:

cargo install diesel_cli --no-default-features --features postgres

Set URL to database

export DATABASE_URL=postgres://<postgres_username>:<postgres_password>@<postgres_host>:<postgres_port>/school

Perform migrations. At this step Rust schema is also automatically generated and printed to the file defined in diesel.toml

diesel setup
diesel migration run

Execute

Put database in vanilla state

diesel migration redo

Run example binary that will query, insert and update tables

cargo run

Tables diagram

alt text

About

Rust Diesel PostgreSQL examples

License:MIT License


Languages

Language:Rust 88.0%Language:PLpgSQL 12.0%