1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! The application's [Toasty](https://github.com/tokio-rs/toasty) database.
//!
//! Models are Rust structs with `#[derive(toasty::Model)]`; this module opens
//! the connection pool they run on, on PostgreSQL. Configure it with
//! `DATABASE_URL` (default [`DEFAULT_URL`]). Several processes and machines
//! can share the database.
//!
//! Schema changes are Toasty migrations: generated from the models by the
//! app's `migrate` binary (built on `toasty-cli`) and applied by it.
use ;
use crateResult;
/// Transaction isolation levels, for [`toasty::TransactionBuilder::isolation`].
/// `Serializable` transactions may fail with a serialization failure under
/// contention; retry them ([`SERIALIZABLE_ATTEMPTS`]).
pub use IsolationLevel;
/// How many times to run a `Serializable` transaction that keeps failing
/// with a serialization failure before giving up.
pub const SERIALIZABLE_ATTEMPTS: usize = 5;
/// Environment variable holding the database URL.
pub const URL_ENV: &str = "DATABASE_URL";
/// The database used when `DATABASE_URL` is not set: a local PostgreSQL.
pub const DEFAULT_URL: &str = "postgresql://localhost:5432/postgres";
/// Where to connect.
/// Opens a pooled handle to the database for `models`. Cheap to clone: clones
/// share the pool.
pub async