Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump SQLx to 0.8 #136

Merged
merged 7 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ sea-schema-derive = { version = "0.3.0", path = "sea-schema-derive", default-fea
sea-query = { version = "0.31.0", default-features = false, features = ["derive"] }
sea-query-binder = { version = "0.6.0", default-features = false, optional = true }
serde = { version = "1", default-features = false, optional = true, features = ["derive"] }
sqlx = { version = "0.7", default-features = false, optional = true }
sqlx = { version = "0.8", default-features = false, optional = true }
log = { version = "0.4", default-features = false, optional = true }

[features]
Expand Down Expand Up @@ -114,3 +114,7 @@ runtime-tokio-rustls = [
"sea-query-binder?/runtime-tokio-rustls",
]
with-serde = ["serde"]

[patch.crates-io]
sea-query = { git = "https://github.com/SeaQL/sea-query", branch = "sqlx-0.8" }
sea-query-binder = { git = "https://github.com/SeaQL/sea-query", branch = "sqlx-0.8" }
19 changes: 18 additions & 1 deletion src/mysql/discovery/executor/real.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sea_query::{MysqlQueryBuilder, SelectStatement};
use sea_query_binder::SqlxBinder;
use sqlx::{mysql::MySqlRow, MySqlPool};
use sqlx::{mysql::MySqlRow, MySqlPool, Row};

use crate::{debug_print, sqlx_types::SqlxError};

Expand Down Expand Up @@ -28,3 +28,20 @@ impl Executor {
.await
}
}

pub trait GetMySqlValue {
fn get_string(&self, idx: usize) -> String;

fn get_string_opt(&self, idx: usize) -> Option<String>;
}

impl GetMySqlValue for MySqlRow {
fn get_string(&self, idx: usize) -> String {
String::from_utf8(self.get::<Vec<u8>, _>(idx)).unwrap()
}

fn get_string_opt(&self, idx: usize) -> Option<String> {
self.get::<Option<Vec<u8>>, _>(idx)
.map(|v| String::from_utf8(v).unwrap())
}
}
18 changes: 9 additions & 9 deletions src/mysql/query/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ impl SchemaQueryBuilder {
#[cfg(feature = "sqlx-mysql")]
impl From<&MySqlRow> for ColumnQueryResult {
fn from(row: &MySqlRow) -> Self {
use crate::sqlx_types::Row;
use crate::mysql::discovery::GetMySqlValue;
Self {
column_name: row.get(0),
column_type: row.get(1),
is_nullable: row.get(2),
column_key: row.get(3),
column_default: row.get(4),
extra: row.get(5),
generation_expression: row.get(6),
column_comment: row.get(7),
column_name: row.get_string(0),
column_type: row.get_string(1),
is_nullable: row.get_string(2),
column_key: row.get_string(3),
column_default: row.get_string_opt(4),
extra: row.get_string(5),
generation_expression: row.get_string_opt(6),
column_comment: row.get_string(7),
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/mysql/query/foreign_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ impl SchemaQueryBuilder {
#[cfg(feature = "sqlx-mysql")]
impl From<&MySqlRow> for ForeignKeyQueryResult {
fn from(row: &MySqlRow) -> Self {
use crate::sqlx_types::Row;
use crate::mysql::discovery::GetMySqlValue;
Self {
constraint_name: row.get(0),
column_name: row.get(1),
referenced_table_name: row.get(2),
referenced_column_name: row.get(3),
update_rule: row.get(4),
delete_rule: row.get(5),
constraint_name: row.get_string(0),
column_name: row.get_string(1),
referenced_table_name: row.get_string(2),
referenced_column_name: row.get_string(3),
update_rule: row.get_string(4),
delete_rule: row.get_string(5),
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/mysql/query/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,18 @@ impl SchemaQueryBuilder {
#[cfg(feature = "sqlx-mysql")]
impl From<&MySqlRow> for IndexQueryResult {
fn from(row: &MySqlRow) -> Self {
use crate::mysql::discovery::GetMySqlValue;
use crate::sqlx_types::Row;
Self {
non_unique: row.get(0),
index_name: row.get(1),
column_name: row.get(2),
collation: row.get(3),
index_name: row.get_string(1),
column_name: row.get_string_opt(2),
collation: row.get_string_opt(3),
sub_part: row.get(4),
nullable: row.get(5),
index_type: row.get(6),
index_comment: row.get(7),
expression: row.get(8),
nullable: row.get_string(5),
index_type: row.get_string(6),
index_comment: row.get_string(7),
expression: row.get_string_opt(8),
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/mysql/query/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ impl SchemaQueryBuilder {
#[cfg(feature = "sqlx-mysql")]
impl From<&MySqlRow> for TableQueryResult {
fn from(row: &MySqlRow) -> Self {
use crate::mysql::discovery::GetMySqlValue;
use crate::sqlx_types::Row;
Self {
table_name: row.get(0),
engine: row.get(1),
table_name: row.get_string(0),
engine: row.get_string(1),
auto_increment: row.get(2),
table_collation: row.get(3),
table_comment: row.get(4),
create_options: row.get(5),
table_char_set: row.get(6),
table_collation: row.get_string(3),
table_comment: row.get_string(4),
create_options: row.get_string(5),
table_char_set: row.get_string(6),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/mysql/query/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ impl SchemaQueryBuilder {
#[cfg(feature = "sqlx-mysql")]
impl From<&MySqlRow> for VersionQueryResult {
fn from(row: &MySqlRow) -> Self {
use crate::sqlx_types::Row;
use crate::mysql::discovery::GetMySqlValue;
Self {
version: row.get(0),
version: row.get_string(0),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/discovery/mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ publish = false
async-std = { version = "1.8", features = [ "attributes", "tokio1" ] }
sea-schema = { path = "../../../", default-features = false, features = [ "with-serde", "sqlx-mysql", "runtime-async-std-native-tls", "discovery", "debug-print" ] }
serde_json = { version = "1" }
sqlx = { version = "0.7" }
sqlx = { version = "0.8" }
env_logger = { version = "0" }
log = { version = "0" }
2 changes: 1 addition & 1 deletion tests/discovery/postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ publish = false
async-std = { version = "1.8", features = [ "attributes", "tokio1" ] }
sea-schema = { path = "../../../", default-features = false, features = [ "with-serde", "sqlx-postgres", "runtime-async-std-native-tls", "discovery", "debug-print" ] }
serde_json = { version = "1" }
sqlx = { version = "0.7" }
sqlx = { version = "0.8" }
env_logger = { version = "0" }
log = { version = "0" }
2 changes: 1 addition & 1 deletion tests/discovery/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ publish = false
async-std = { version = "1.8", features = [ "attributes", "tokio1" ] }
sea-schema = { path = "../../../", default-features = false, features = [ "with-serde", "sqlx-sqlite", "runtime-async-std-native-tls", "discovery", "debug-print" ] }
serde_json = { version = "1" }
sqlx = { version = "0.7" }
sqlx = { version = "0.8" }
2 changes: 1 addition & 1 deletion tests/live/mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
async-std = { version = "1.8", features = [ "attributes", "tokio1" ] }
sea-schema = { path = "../../../", default-features = false, features = [ "sqlx-mysql", "runtime-async-std-native-tls", "discovery", "writer", "debug-print" ] }
serde_json = { version = "1" }
sqlx = { version = "0.7" }
sqlx = { version = "0.8" }
pretty_assertions = { version = "0.7" }
regex = { version = "1" }
env_logger = { version = "0" }
Expand Down
2 changes: 1 addition & 1 deletion tests/live/postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
async-std = { version = "1.8", features = [ "attributes", "tokio1" ] }
sea-schema = { path = "../../../", default-features = false, features = [ "sqlx-postgres", "runtime-async-std-native-tls", "discovery", "writer", "debug-print" ] }
serde_json = { version = "1" }
sqlx = { version = "0.7" }
sqlx = { version = "0.8" }
env_logger = { version = "0" }
log = { version = "0" }
pretty_assertions = { version = "0.7" }
2 changes: 1 addition & 1 deletion tests/live/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sea-schema = { path = "../../../", default-features = false, features = [
"sqlite",
] }
serde_json = { version = "1" }
sqlx = { version = "0.7", features = [
sqlx = { version = "0.8", features = [
"sqlite",
"runtime-async-std-native-tls",
] }
Expand Down
2 changes: 1 addition & 1 deletion tests/writer/mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ publish = false
async-std = { version = "1.8", features = [ "attributes", "tokio1" ] }
sea-schema = { path = "../../../", default-features = false, features = [ "sqlx-mysql", "runtime-async-std-native-tls", "discovery", "writer", "debug-print" ] }
serde_json = { version = "1" }
sqlx = { version = "0.7" }
sqlx = { version = "0.8" }
env_logger = { version = "0" }
log = { version = "0" }
2 changes: 1 addition & 1 deletion tests/writer/postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ pretty_assertions = { version = "0.7" }
async-std = { version = "1.8", features = [ "attributes", "tokio1" ] }
sea-schema = { path = "../../../", default-features = false, features = [ "sqlx-postgres", "runtime-async-std-native-tls", "discovery", "writer", "debug-print" ] }
serde_json = { version = "1" }
sqlx = { version = "0.7" }
sqlx = { version = "0.8" }
env_logger = { version = "0" }
log = { version = "0" }
2 changes: 1 addition & 1 deletion tests/writer/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ publish = false
async-std = { version = "1.8", features = [ "attributes", "tokio1" ] }
sea-schema = { path = "../../../", default-features = false, features = [ "sqlx-sqlite", "runtime-async-std-native-tls", "discovery", "writer", "debug-print" ] }
serde_json = { version = "1" }
sqlx = { version = "0.7" }
sqlx = { version = "0.8" }
Loading