tank-postgres 0.49.0

Postgres driver implementation for Tank: the Rust data layer
Documentation

tank-postgres

tank-postgres is the Postgres driver for Tank: the Rust data layer.

It maps Tank operations and queries to native Postgres commands. Use it with the main tank crate, which provides entity definitions and the query API.

📘 Docs: https://tankhq.github.io/tank

🖥️ Repo: https://github.com/TankHQ/tank

📦 Crate: https://crates.io/crates/tank-postgres

Features

Install

cargo add tank
cargo add tank-postgres

Quick Start

use tank::{ConnectionPool, Driver, PoolConfig};
use tank_postgres::PostgresDriver;

let driver = PostgresDriver::new();
let pool = driver
    .connect_pool(
        "postgres://user:password@127.0.0.1:5432/database?sslmode=require&sslrootcert=root.crt&sslcert=client.crt&sslkey=client.key",
        PoolConfig::new(),
    )
    .await?;
let mut connection = pool.get().await?;

Run this inside an async function. The returned connection can execute Tank entity operations.

Certificate filenames are resolved relative to the working directory. Use paths appropriate for your deployment.

Running Tests

The tests manage their own throwaway containers via testcontainers-modules. No database setup is needed. Set environment variable TANK_POSTGRES_TEST to use your own server.

Docker is required:

  1. Ensure Docker is running on Linux:
systemctl status docker
  1. Add your user to the docker group if needed on Linux:
sudo usermod -aG docker $USER

[!CAUTION] Avoid aborting tests mid-run (e.g. killing the process at a breakpoint). Containers might be left running and consume resources.

List containers:

docker ps

Stop container:

docker kill <container_id_or_name>