dovecote_sqlx_postgres/
lib.rs1#![warn(missing_docs)]
10
11mod delivery_state;
12mod enqueue;
13mod error;
14mod finalize;
15mod hydrate;
16mod import;
17mod lifecycle;
18mod lifecycle_mutation;
19mod migration;
20mod page;
21mod rls;
22mod schema;
23mod scope;
24
25pub use error::{
26 ClaimError, EnqueueError, FinalizeError, ImportError, MutationError, PageError, SchemaError,
27 TransientKind,
28};
29pub use migration::{
30 CrateVersion, LEGACY_MIGRATION, MIGRATIONS, Migration, MigrationCompatibility,
31 MigrationCompatibilityError, SCHEMA_VERSION, V1_TENANT_ACTIVATE_SQL, V1_TENANT_PREPARE_SQL,
32};
33pub use page::SnapshotPager;
34pub use rls::{RLS_PROFILE_SQL, bind_tenant};
35pub use schema::check_schema;
36
37use sqlx::PgPool;
38
39pub use scope::{AdminDovecote, TenantDovecote};
40
41#[derive(Clone)]
43pub struct PostgresDovecote {
44 pool: PgPool,
45}
46
47impl PostgresDovecote {
48 pub fn new(pool: PgPool) -> Self {
50 Self { pool }
51 }
52
53 pub fn pool(&self) -> &PgPool {
55 &self.pool
56 }
57
58 pub fn for_tenant(&self, tenant: dovecote::TenantId) -> TenantDovecote {
60 TenantDovecote::new(self.pool.clone(), tenant)
61 }
62
63 pub fn admin(&self) -> AdminDovecote {
68 AdminDovecote::new(self.pool.clone())
69 }
70
71 pub async fn check_schema(&self) -> Result<(), SchemaError> {
74 check_schema(&self.pool).await
75 }
76}