sea-schema 0.18.0

🌿 SQL schema definition and discovery
Documentation
pub use sqlx::*;

pub type SqlxError = sqlx::Error;

#[cfg(not(feature = "sqlx-mysql"))]
pub struct MySqlPool;

#[cfg(not(feature = "sqlx-postgres"))]
pub struct PgPool;

#[cfg(not(feature = "sqlx-sqlite"))]
pub struct SqlitePool;

pub enum SqlxRow {
    #[cfg(feature = "sqlx-mysql")]
    MySql(sqlx::mysql::MySqlRow),
    #[cfg(feature = "sqlx-postgres")]
    Postgres(sqlx::postgres::PgRow),
    #[cfg(feature = "sqlx-sqlite")]
    Sqlite(sqlx::sqlite::SqliteRow),
}

#[allow(unreachable_patterns)]
impl SqlxRow {
    #[cfg(feature = "sqlx-mysql")]
    pub fn mysql(self) -> mysql::MySqlRow {
        match self {
            Self::MySql(row) => row,
            _ => panic!("Not MySql"),
        }
    }

    #[cfg(feature = "sqlx-postgres")]
    pub fn postgres(self) -> postgres::PgRow {
        match self {
            Self::Postgres(row) => row,
            _ => panic!("Not Postgres"),
        }
    }

    #[cfg(feature = "sqlx-sqlite")]
    pub fn sqlite(self) -> sqlite::SqliteRow {
        match self {
            Self::Sqlite(row) => row,
            _ => panic!("Not Sqlite"),
        }
    }
}

#[cfg(feature = "sqlx-sqlite")]
pub async fn connect_sqlite(s: &str) -> Result<SqlitePool, SqlxError> {
    SqlitePool::connect(s).await
}

#[cfg(feature = "sqlx-sqlite")]
pub async fn execute_sqlite(pool: &SqlitePool, sql: &str) -> Result<(), SqlxError> {
    sqlx::query(sqlx::AssertSqlSafe(sql)).execute(pool).await?;
    Ok(())
}