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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use std::collections::HashMap;

use crate::{Query, QueryBuilderTrait, TableBuilder, Value};

/// GeekConnection
pub trait GeekConnection
where
    Self: Sized,
{
    /// Native connection type
    type Connection;
    /// Native error type
    type Error;
    /// Native statement
    type Statement;

    /// Execute a query on the database
    #[allow(async_fn_in_trait, unused_variables)]
    async fn prepare(&self, query: &str) -> Result<Self::Statement, Self::Error>;
}

/// This module contains the LibSQL backend
#[cfg(feature = "libsql")]
pub mod libsql;

/// This trait is used to define the connection to the database.
///
/// The main focus of this trait is to provide a way to connect to the database for any Table that
/// implements it.
pub trait GeekConnector
where
    Self: TableBuilder + QueryBuilderTrait + Sized + serde::Serialize + serde::de::DeserializeOwned,
{
    /// The connection type
    type Connection;
    /// The row
    type Row;
    /// The rows to return type
    type Rows;

    /// Create a table in the database
    #[allow(async_fn_in_trait, unused_variables)]
    async fn create_table(connection: &Self::Connection) -> Result<(), crate::Error> {
        Err(crate::Error::NotImplemented)
    }

    /// Run a SELECT Count query on the database and return the number of rows
    #[allow(async_fn_in_trait, unused_variables)]
    async fn row_count(connection: &Self::Connection, query: Query) -> Result<i64, crate::Error> {
        Err(crate::Error::NotImplemented)
    }

    /// Execute a query on the database and do not return any rows
    #[allow(async_fn_in_trait, unused_variables)]
    async fn execute(connection: &Self::Connection, query: Query) -> Result<(), crate::Error> {
        Err(crate::Error::NotImplemented)
    }

    /// Query the database with an active Connection and Query
    #[allow(async_fn_in_trait, unused_variables)]
    async fn query(
        connection: &Self::Connection,
        query: Query,
    ) -> Result<Self::Rows, crate::Error> {
        Err(crate::Error::NotImplemented)
    }

    /// Query the database with an active Connection and Query and return the first row.
    ///
    /// Note: Make sure the query is limited to 1 row to avoid retrieving multiple rows
    /// and only using the first one.
    #[allow(async_fn_in_trait, unused_variables)]
    async fn query_first(
        connection: &Self::Connection,
        query: Query,
    ) -> Result<Self::Row, crate::Error> {
        Err(crate::Error::NotImplemented)
    }

    /// Query the database with an active Connection and Query and return a list of GeekORM Values.
    #[allow(async_fn_in_trait, unused_variables)]
    async fn query_raw(
        connection: &Self::Connection,
        query: Query,
    ) -> Result<Vec<HashMap<String, Value>>, crate::Error> {
        Err(crate::Error::NotImplemented)
    }
}