Skip to content

Commit

Permalink
Bump SeaQuery to 0.27 (#81)
Browse files Browse the repository at this point in the history
* Bump SeaQuery to 0.27

* Fixup

* Fixup

* Fixup

* Fixup

* Fixup

* Depends on SeaQuery github master

* Bump SeaSchema version to 0.10.0
  • Loading branch information
billy1624 authored Oct 18, 2022
1 parent 9f06079 commit ffcb236
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 37 deletions.
41 changes: 30 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [

[package]
name = "sea-schema"
version = "0.9.4"
version = "0.10.0"
authors = [ "Chris Tsang <[email protected]>" ]
edition = "2021"
description = "🌿 SQL schema definition and discovery"
Expand All @@ -35,7 +35,8 @@ path = "src/lib.rs"
[dependencies]
futures = { version = "0.3", optional = true }
sea-schema-derive = { version = "0.1.0", path = "sea-schema-derive" }
sea-query = { version = "^0.26.0" }
sea-query = { version = "^0.27", git = "https://github.com/SeaQL/sea-query" }
sea-query-binder = { version = "^0.2", optional = true, git = "https://github.com/SeaQL/sea-query" }
serde = { version = "^1", features = ["derive"], optional = true }
sqlx = { version = "^0.6", optional = true }
log = { version = "^0.4", optional = true }
Expand All @@ -58,27 +59,45 @@ sqlx-mysql = [
"mysql",
"futures",
"sqlx-dep",
"sea-query/sqlx-mysql",
"sea-query-binder/sqlx-mysql",
"sqlx/mysql",
]
sqlx-postgres = [
"postgres",
"futures",
"sqlx-dep",
"sea-query/sqlx-postgres",
"sea-query-binder/sqlx-postgres",
"sqlx/postgres",
]
sqlx-sqlite = [
"sqlite",
"futures",
"sqlx-dep",
"sea-query/sqlx-sqlite",
"sea-query-binder/sqlx-sqlite",
"sqlx/sqlite",
]
runtime-actix-native-tls = ["sqlx/runtime-actix-native-tls"]
runtime-async-std-native-tls = ["sqlx/runtime-async-std-native-tls"]
runtime-tokio-native-tls = ["sqlx/runtime-tokio-native-tls"]
runtime-actix-rustls = ["sqlx/runtime-actix-rustls"]
runtime-async-std-rustls = ["sqlx/runtime-async-std-rustls"]
runtime-tokio-rustls = ["sqlx/runtime-tokio-rustls"]
runtime-actix-native-tls = [
"sqlx/runtime-actix-native-tls",
"sea-query-binder/runtime-actix-native-tls",
]
runtime-async-std-native-tls = [
"sqlx/runtime-async-std-native-tls",
"sea-query-binder/runtime-async-std-native-tls",
]
runtime-tokio-native-tls = [
"sqlx/runtime-tokio-native-tls",
"sea-query-binder/runtime-tokio-native-tls",
]
runtime-actix-rustls = [
"sqlx/runtime-actix-rustls",
"sea-query-binder/runtime-actix-rustls",
]
runtime-async-std-rustls = [
"sqlx/runtime-async-std-rustls",
"sea-query-binder/runtime-async-std-rustls",
]
runtime-tokio-rustls = [
"sqlx/runtime-tokio-rustls",
"sea-query-binder/runtime-tokio-rustls",
]
with-serde = ["serde"]
9 changes: 3 additions & 6 deletions src/mysql/discovery/executor/real.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use sea_query::{MysqlQueryBuilder, SelectStatement};
use sea_query_binder::SqlxBinder;
use sqlx::{mysql::MySqlRow, MySqlPool};

sea_query::sea_query_driver_mysql!();
use sea_query_driver_mysql::bind_query;

use crate::debug_print;

pub struct Executor {
Expand All @@ -22,11 +20,10 @@ impl IntoExecutor for MySqlPool {

impl Executor {
pub async fn fetch_all(&self, select: SelectStatement) -> Vec<MySqlRow> {
let (sql, values) = select.build(MysqlQueryBuilder);
let (sql, values) = select.build_sqlx(MysqlQueryBuilder);
debug_print!("{}, {:?}", sql, values);

let query = bind_query(sqlx::query(&sql), &values);
query
sqlx::query_with(&sql, values)
.fetch_all(&mut self.pool.acquire().await.unwrap())
.await
.unwrap()
Expand Down
1 change: 0 additions & 1 deletion src/mysql/query/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use sea_query::{Func, Query, SelectStatement};

#[derive(sea_query::Iden)]
enum MysqlFunc {
#[iden = "version()"]
Version,
}

Expand Down
12 changes: 10 additions & 2 deletions src/mysql/writer/column.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::mysql::def::{CharSet, ColumnInfo, NumericAttr, StringAttr, Type};
use sea_query::{Alias, BlobSize, ColumnDef, EscapeBuilder, Iden, MysqlQueryBuilder};
use sea_query::{
Alias, BlobSize, ColumnDef, DynIden, EscapeBuilder, Iden, IntoIden, MysqlQueryBuilder,
};
use std::fmt::Write;

impl ColumnInfo {
Expand Down Expand Up @@ -232,7 +234,13 @@ impl ColumnInfo {
col_def.blob(BlobSize::Long);
}
Type::Enum(enum_attr) => {
col_def.enumeration(&self.name, &enum_attr.values);
let name = Alias::new(&self.name);
let variants: Vec<DynIden> = enum_attr
.values
.iter()
.map(|variant| Alias::new(variant).into_iden())
.collect();
col_def.enumeration(name, variants);
}
Type::Set(_) => {
// FIXME: Unresolved type mapping
Expand Down
9 changes: 3 additions & 6 deletions src/postgres/discovery/executor/real.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use sea_query::{PostgresQueryBuilder, SelectStatement};
use sea_query_binder::SqlxBinder;
use sqlx::{postgres::PgRow, PgPool};

sea_query::sea_query_driver_postgres!();
use sea_query_driver_postgres::bind_query;

use crate::debug_print;

pub struct Executor {
Expand All @@ -22,11 +20,10 @@ impl IntoExecutor for PgPool {

impl Executor {
pub async fn fetch_all(&self, select: SelectStatement) -> Vec<PgRow> {
let (sql, values) = select.build(PostgresQueryBuilder);
let (sql, values) = select.build_sqlx(PostgresQueryBuilder);
debug_print!("{}, {:?}", sql, values);

let query = bind_query(sqlx::query(&sql), &values);
query
sqlx::query_with(&sql, values)
.fetch_all(&mut self.pool.acquire().await.unwrap())
.await
.unwrap()
Expand Down
10 changes: 8 additions & 2 deletions src/postgres/writer/column.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::postgres::def::{ColumnInfo, Type};
use sea_query::{Alias, ColumnDef, PgInterval};
use sea_query::{Alias, ColumnDef, DynIden, IntoIden, PgInterval};
use std::{convert::TryFrom, fmt::Write};

impl ColumnInfo {
Expand Down Expand Up @@ -233,7 +233,13 @@ impl ColumnInfo {
col_def.custom(Alias::new(s));
}
Type::Enum(enum_def) => {
col_def.enumeration(&enum_def.typename, &enum_def.values);
let name = Alias::new(&enum_def.typename);
let variants: Vec<DynIden> = enum_def
.values
.iter()
.map(|variant| Alias::new(variant).into_iden())
.collect();
col_def.enumeration(name, variants);
}
};
col_def
Expand Down
14 changes: 5 additions & 9 deletions src/sqlite/executor/real.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use sea_query::{SelectStatement, SqliteQueryBuilder};
use sea_query_binder::SqlxBinder;
use sqlx::{sqlite::SqliteRow, SqlitePool};

sea_query::sea_query_driver_sqlite!();
use sea_query_driver_sqlite::bind_query;

use crate::debug_print;

pub struct Executor {
Expand All @@ -22,22 +20,20 @@ impl IntoExecutor for SqlitePool {

impl Executor {
pub async fn fetch_all(&self, select: SelectStatement) -> Vec<SqliteRow> {
let (sql, values) = select.build(SqliteQueryBuilder);
let (sql, values) = select.build_sqlx(SqliteQueryBuilder);
debug_print!("{}, {:?}", sql, values);

let query = bind_query(sqlx::query(&sql), &values);
query
sqlx::query_with(&sql, values)
.fetch_all(&mut self.pool.acquire().await.unwrap())
.await
.unwrap()
}

pub async fn fetch_one(&self, select: SelectStatement) -> SqliteRow {
let (sql, values) = select.build(SqliteQueryBuilder);
let (sql, values) = select.build_sqlx(SqliteQueryBuilder);
debug_print!("{}, {:?}", sql, values);

let query = bind_query(sqlx::query(&sql), &values);
query
sqlx::query_with(&sql, values)
.fetch_one(&mut self.pool.acquire().await.unwrap())
.await
.unwrap()
Expand Down

0 comments on commit ffcb236

Please sign in to comment.