db_core/ops.rs
1// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
2// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
3//
4// SPDX-License-Identifier: AGPL-3.0-or-later
5
6//! meta operations like migration and connecting to a database
7use crate::dev::*;
8
9/// Database operations trait(migrations, pool creation and fetching connection from pool)
10pub trait DBOps: GetConnection + Migrate {}
11
12/// Get database connection
13#[async_trait]
14pub trait GetConnection {
15 /// database connection type
16 type Conn;
17 /// database specific error-type
18 /// get connection from connection pool
19 async fn get_conn(&self) -> DBResult<Self::Conn>;
20}
21
22/// Create database connection
23#[async_trait]
24pub trait Connect {
25 /// database specific pool-type
26 type Pool: MCDatabase;
27 /// database specific error-type
28 /// create connection pool
29 async fn connect(self) -> DBResult<Self::Pool>;
30}
31
32/// database migrations
33#[async_trait]
34pub trait Migrate: MCDatabase {
35 /// database specific error-type
36 /// run migrations
37 async fn migrate(&self) -> DBResult<()>;
38}