forked from
slices.network/slices
Highly ambitious ATProtocol AppView service and sdks
1use sqlx::PgPool;
2
3/// Core database client for interacting with PostgreSQL.
4///
5/// The Database struct wraps a connection pool and provides methods for
6/// all database operations across records, actors, slices, OAuth, and analytics.
7#[derive(Clone)]
8pub struct Database {
9 pub(super) pool: PgPool,
10}
11
12impl Database {
13 /// Creates a new Database instance from a connection pool.
14 pub fn new(pool: PgPool) -> Self {
15 Self { pool }
16 }
17
18 /// Creates a new Database instance from a connection pool.
19 /// Alias for `new()` for clarity in some contexts.
20 pub fn from_pool(pool: PgPool) -> Self {
21 Self::new(pool)
22 }
23
24 /// Gets a reference to the connection pool.
25 pub fn pool(&self) -> &PgPool {
26 &self.pool
27 }
28
29 /// Gets jetstream logs from the database
30 ///
31 /// # Arguments
32 /// * `slice_filter` - Optional slice URI to filter logs
33 /// * `limit` - Optional maximum number of logs to return (default: 100)
34 ///
35 /// # Returns
36 /// * `Ok(Vec<LogEntry>)` - List of log entries ordered by creation time (DESC)
37 /// * `Err(sqlx::Error)` - Database query error
38 pub async fn get_jetstream_logs(
39 &self,
40 slice_filter: Option<&str>,
41 limit: Option<i64>,
42 ) -> Result<Vec<crate::logging::LogEntry>, sqlx::Error> {
43 crate::logging::get_jetstream_logs(&self.pool, slice_filter, limit).await
44 }
45}