parent
1eb0e5cbb2
commit
86f2d7e327
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ target
|
|||||||
Cargo.lock
|
Cargo.lock
|
||||||
*.sublime*
|
*.sublime*
|
||||||
.vscode
|
.vscode
|
||||||
|
.idea/*
|
@ -56,7 +56,7 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
|
|||||||
.filter(|schema| filter_hidden_tables(&schema.info.name))
|
.filter(|schema| filter_hidden_tables(&schema.info.name))
|
||||||
.map(|schema| schema.write())
|
.map(|schema| schema.write())
|
||||||
.collect()
|
.collect()
|
||||||
} else if url.starts_with("postgres://") {
|
} else if url.starts_with("postgres://") || url.starts_with("postgresql://") {
|
||||||
use sea_schema::postgres::discovery::SchemaDiscovery;
|
use sea_schema::postgres::discovery::SchemaDiscovery;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
@ -12,21 +12,40 @@ pub use transaction::*;
|
|||||||
|
|
||||||
use crate::DbErr;
|
use crate::DbErr;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum DbScheme {
|
||||||
|
Postgres,
|
||||||
|
Mysql,
|
||||||
|
Sqlite,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DbScheme {
|
||||||
|
pub fn starts_with(self, base_url: &str) -> bool {
|
||||||
|
match self {
|
||||||
|
DbScheme::Postgres => {
|
||||||
|
base_url.starts_with("postgres://") || base_url.starts_with("postgresql://")
|
||||||
|
}
|
||||||
|
DbScheme::Mysql => base_url.starts_with("mysql://"),
|
||||||
|
DbScheme::Sqlite => base_url.starts_with("sqlite:"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Database;
|
pub struct Database;
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
||||||
#[cfg(feature = "sqlx-mysql")]
|
#[cfg(feature = "sqlx-mysql")]
|
||||||
if crate::SqlxMySqlConnector::accepts(string) {
|
if DbScheme::Mysql::starts_with(string) {
|
||||||
return crate::SqlxMySqlConnector::connect(string).await;
|
return crate::SqlxMySqlConnector::connect(string).await;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
if crate::SqlxPostgresConnector::accepts(string) {
|
if DbScheme::Postgres::starts_with(string) {
|
||||||
return crate::SqlxPostgresConnector::connect(string).await;
|
return crate::SqlxPostgresConnector::connect(string).await;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-sqlite")]
|
#[cfg(feature = "sqlx-sqlite")]
|
||||||
if crate::SqlxSqliteConnector::accepts(string) {
|
if DbScheme::Sqlite::starts_with(string) {
|
||||||
return crate::SqlxSqliteConnector::connect(string).await;
|
return crate::SqlxSqliteConnector::connect(string).await;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
debug_print, error::*, DatabaseConnection, DbBackend, ExecResult, MockDatabase, QueryResult,
|
debug_print, error::*, DatabaseConnection, DbBackend, ExecResult, MockDatabase,
|
||||||
Statement, Transaction,
|
QueryResult, Statement, Transaction,
|
||||||
};
|
};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
@ -31,15 +31,15 @@ impl MockDatabaseConnector {
|
|||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub fn accepts(string: &str) -> bool {
|
pub fn accepts(string: &str) -> bool {
|
||||||
#[cfg(feature = "sqlx-mysql")]
|
#[cfg(feature = "sqlx-mysql")]
|
||||||
if crate::SqlxMySqlConnector::accepts(string) {
|
if DbScheme::Mysql::accepts(string) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-postgres")]
|
#[cfg(feature = "sqlx-postgres")]
|
||||||
if crate::SqlxPostgresConnector::accepts(string) {
|
if DbScheme::Postgres::accepts(string) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sqlx-sqlite")]
|
#[cfg(feature = "sqlx-sqlite")]
|
||||||
if crate::SqlxSqliteConnector::accepts(string) {
|
if DbScheme::Sqlite::accepts(string) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
@ -6,7 +6,7 @@ use sqlx::{
|
|||||||
sea_query::sea_query_driver_mysql!();
|
sea_query::sea_query_driver_mysql!();
|
||||||
use sea_query_driver_mysql::bind_query;
|
use sea_query_driver_mysql::bind_query;
|
||||||
|
|
||||||
use crate::{debug_print, error::*, executor::*, DatabaseConnection, Statement};
|
use crate::{debug_print, error::*, executor::*, DatabaseConnection, DbScheme, Statement};
|
||||||
|
|
||||||
use super::sqlx_common::*;
|
use super::sqlx_common::*;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ pub struct SqlxMySqlPoolConnection {
|
|||||||
|
|
||||||
impl SqlxMySqlConnector {
|
impl SqlxMySqlConnector {
|
||||||
pub fn accepts(string: &str) -> bool {
|
pub fn accepts(string: &str) -> bool {
|
||||||
string.starts_with("mysql://")
|
DbScheme::Mysql::starts_with(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
||||||
|
@ -6,7 +6,7 @@ use sqlx::{
|
|||||||
sea_query::sea_query_driver_postgres!();
|
sea_query::sea_query_driver_postgres!();
|
||||||
use sea_query_driver_postgres::bind_query;
|
use sea_query_driver_postgres::bind_query;
|
||||||
|
|
||||||
use crate::{debug_print, error::*, executor::*, DatabaseConnection, Statement};
|
use crate::{debug_print, error::*, executor::*, DatabaseConnection, DbScheme, Statement};
|
||||||
|
|
||||||
use super::sqlx_common::*;
|
use super::sqlx_common::*;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ pub struct SqlxPostgresPoolConnection {
|
|||||||
|
|
||||||
impl SqlxPostgresConnector {
|
impl SqlxPostgresConnector {
|
||||||
pub fn accepts(string: &str) -> bool {
|
pub fn accepts(string: &str) -> bool {
|
||||||
string.starts_with("postgres://")
|
DbScheme::Postgres::starts_with(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
||||||
|
@ -6,7 +6,7 @@ use sqlx::{
|
|||||||
sea_query::sea_query_driver_sqlite!();
|
sea_query::sea_query_driver_sqlite!();
|
||||||
use sea_query_driver_sqlite::bind_query;
|
use sea_query_driver_sqlite::bind_query;
|
||||||
|
|
||||||
use crate::{debug_print, error::*, executor::*, DatabaseConnection, Statement};
|
use crate::{debug_print, error::*, executor::*, DatabaseConnection, DbScheme, Statement};
|
||||||
|
|
||||||
use super::sqlx_common::*;
|
use super::sqlx_common::*;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ pub struct SqlxSqlitePoolConnection {
|
|||||||
|
|
||||||
impl SqlxSqliteConnector {
|
impl SqlxSqliteConnector {
|
||||||
pub fn accepts(string: &str) -> bool {
|
pub fn accepts(string: &str) -> bool {
|
||||||
string.starts_with("sqlite:")
|
DbScheme::Sqlite::starts_with(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user