Skip to content

sandbox for using multiple database instances for Rust

Notifications You must be signed in to change notification settings

nrskt/multi-db-conn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sandbox for using multiple database in Rust

How to run

1. Setup diesel

See diesel official documentation and install client(diesel-cli).

Doc: https://diesel.rs/guides/getting-started.html

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

2. Start two PostgreSQL containers by docker-compose

docker compose up -d

3. Migrate the databases and insert sample data

$ diesel migration run --database-url postgres://postgres:password1@localhost:15432/docker
$ diesel migration run --database-url postgres://postgres:password2@localhost:15433/docker
$ psql postgres://postgres:password1@localhost:15432/docker -c "insert into sample_user values (1, 1, 'this is tenant_1')"
$ psql postgres://postgres:password2@localhost:15433/docker -c "insert into sample_user values (1, 2, 'this is tenant_2')"

4. Run sample code

$ cargo run

You can get the following results.

tenant_id: 1
Ok(
    [
        SampleUser {
            id: 1,
            tenant_id: 1,
            value: "this is tenant_1",
        },
    ],
)
tenant_id: 2
Ok(
    [
        SampleUser {
            id: 1,
            tenant_id: 2,
            value: "this is tenant_2",
        },
    ],
)

About

sandbox for using multiple database instances for Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages