Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

API Decision Guide

Quick reference: “I want to do X → use Y.”


Connecting

I want to…Use
Connect with just host/port/user/dbPgDriver::connect()
Connect with a passwordPgDriver::connect_with_password()
Use DATABASE_URL from envPgDriver::connect_env()
Connect over TLS (cloud DB)PgConnection::connect_tls()
Use client certificates (mTLS)PgConnection::connect_mtls()
Connect via Unix socketPgConnection::connect_unix()
Customize everythingPgDriver::builder()
Run a production serverPgPool::connect(config)

Querying

I want to…Use
Get rows backdriver.fetch_all(&cmd)
Get exactly one rowdriver.fetch_one(&cmd)
Run a mutation (INSERT/UPDATE/DELETE)driver.execute(&cmd)
Use SQL text anyway (outside qail-pg)tokio-postgres / sqlx for that service

Bulk Operations

I want to…Use
Insert thousands of rows fastdriver.copy_bulk(&cmd, &rows) (COPY protocol)
Pipeline many inserts (no results needed)driver.pipeline_ast_fast(&commands)
Pipeline inserts (need the inserted rows)driver.pipeline_ast(&commands)
Pipeline the same query shape with many param setsdriver.pipeline_ast_cached(&commands)

Connection Pool

I want to…Use
Get a pooled connectionpool.acquire()
Get a connection with RLS tenant contextpool.acquire_with_rls(&ctx)
Check pool statuspool.idle_count(), pool.stats()

Transactions

I want to…Use
Start a transactionconn.begin_transaction()
Commitconn.commit()
Roll backconn.rollback()

Multi-Tenant (RLS)

I want to…Use
Set tenant context on connectionpool.acquire_with_rls(&ctx)
Manually set RLSdriver.set_rls_context(&ctx)
Clear RLS contextdriver.clear_rls_context()
Define RLS policies in schemapolicy name on table for select using $$ ... $$ in .qail
Generate RLS setup SQLrls_setup_sql(&table, &policy)

Performance Tips

  1. Use the poolPgPool reuses connections and caches prepared statements.
  2. Use pipeline_ast_fast() for bulk mutations — one round-trip instead of N.
  3. Use copy_bulk() for truly massive inserts (>10K rows) — 10x faster than pipelining.
  4. Use fetch_all() (cached) not fetch_all_uncached() — statement caching gives ~2x speedup.
  5. Use acquire_with_rls() in multi-tenant apps — auto-clears on Drop, prevents cross-tenant leaks.