User DDD Example

DDD without repository pattern, see [https://softwareengineering.stackexchange.com/questions/441348/in-the-oo-ddd-does-the-domain-object-access-the-repository-directly]

Setup

  1. Create .env file if needed. Run docker-compose up -d to run Postgres in the background.

  2. Declare the database URL

    export DATABASE_URL="postgres://postgres:password@localhost/users"

    Access from command line like:

    psql postgresql://postgres:password@localhost/users -c 'select * from users'
  3. Create the database.

    sqlx db create
  4. Run sql migrations

    sqlx migrate run

Usage

cargo run

Query DB from shell

psql postgresql://postgres:password@localhost/users -c 'select * from users'