-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trying a few things before arriving at a fix which is a patch to sqlx
PR launchbadge/sqlx#2688 split has_decimal binaries into separate files add view_type table which contains a bool column which causes issues
- Loading branch information
1 parent
099cc01
commit a2a726c
Showing
24 changed files
with
1,050 additions
and
89 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,8 @@ edition = "2021" | |
authors = ["Cameron <[email protected]>"] | ||
|
||
[workspace.dependencies] | ||
|
||
[patch.crates-io] | ||
# sqlx = { path = "../sqlx"} | ||
sqlx = { git = "https://github.com/cameronbraid/sqlx", branch = "decimal_compatibility_lenient" } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use app::docker; | ||
use color_eyre::Result; | ||
use entity::has_decimal; | ||
use mysql::Pool; | ||
use mysql::prelude::FromRow; | ||
use rust_decimal::Decimal; | ||
|
||
use mysql::prelude::Queryable; | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
|
||
#[derive(FromRow, Debug)] | ||
pub struct Row { | ||
pub id : i64, | ||
pub price: Decimal, | ||
} | ||
|
||
let url = "mysql://user:password@localhost:3307/db?enable_cleartext_plugin=true"; | ||
let pool = Pool::new(url)?; | ||
|
||
let mut conn = pool.get_conn()?; | ||
let row: Option<Row> = conn | ||
.exec_first( | ||
"SELECT * from has_decimal",())?; | ||
|
||
println!("row: {:?}", row); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use app::docker; | ||
use color_eyre::Result; | ||
use entity::has_decimal; | ||
use rust_decimal_macros::dec; | ||
use sea_orm::ActiveModelTrait; | ||
use sea_orm::EntityTrait; | ||
use sea_orm::Set; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let db = docker::db_connect().await; | ||
|
||
let item = has_decimal::ActiveModel { | ||
id: Set(1), | ||
price: Set(dec!(10.0)), | ||
} | ||
.insert(&db.mysql) | ||
.await?; | ||
|
||
println!("item: {:?}", item); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use app::docker; | ||
use color_eyre::Result; | ||
use entity::has_decimal; | ||
use rust_decimal_macros::dec; | ||
use sea_orm::ActiveModelTrait; | ||
use sea_orm::EntityTrait; | ||
use sea_orm::Set; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let db = docker::db_connect().await; | ||
|
||
let item = has_decimal::Entity::find_by_id(1).one(&db.mysql).await?; | ||
|
||
println!("item: {:?}", item); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use app::docker; | ||
use color_eyre::Result; | ||
use entity::has_decimal; | ||
use sea_orm::EntityTrait; | ||
|
||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let db = docker::db_connect().await; | ||
|
||
let item = has_decimal::Entity::find_by_id(1) | ||
.one(&db.readyset) | ||
.await? | ||
.ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; | ||
println!("item: {:?}", item); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use color_eyre::Result; | ||
use rust_decimal::Decimal; | ||
use sqlx::{MySqlPool, types::BigDecimal}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
|
||
let pool = MySqlPool::connect("mysql://user:password@localhost:3307/db?ssl-mode=disabled").await?; | ||
|
||
#[derive(sqlx::FromRow, Debug)] | ||
pub struct Row { | ||
pub id : i64, | ||
pub price: Decimal, | ||
} | ||
|
||
// Make a simple query to return the given parameter (use a question mark `?` instead of `$1` for MySQL) | ||
let row : Row = sqlx::query_as("SELECT id, price from has_decimal") | ||
.fetch_one(&pool).await?; | ||
|
||
println!("row: {:?}", row); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use color_eyre::Result; | ||
use rust_decimal::Decimal; | ||
use sqlx::MySqlPool; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let pool = | ||
MySqlPool::connect("mysql://user:password@localhost:3307/db?ssl-mode=disabled").await?; | ||
|
||
#[derive(sqlx::FromRow, Debug)] | ||
pub struct Row { | ||
pub id: i64, | ||
pub price: Decimal, | ||
} | ||
|
||
// Make a simple query to return the given parameter (use a question mark `?` instead of `$1` for MySQL) | ||
let row: Row = sqlx::query_as("SELECT id, price from has_decimal") | ||
.fetch_one(&pool) | ||
.await?; | ||
|
||
println!("row: {:?}", row); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use app::docker; | ||
use color_eyre::Result; | ||
use entity::product; | ||
use sea_orm::ActiveModelTrait; | ||
use sea_orm::ColumnTrait; | ||
use sea_orm::DbBackend; | ||
use sea_orm::EntityTrait; | ||
use sea_orm::FromQueryResult; | ||
use sea_orm::QueryFilter; | ||
use sea_orm::Set; | ||
use sea_orm::Statement; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let db = docker::db_connect().await; | ||
|
||
let item = product::Entity::find_by_id(1).one(&db.mysql).await?; | ||
|
||
if item.is_none() { | ||
product::ActiveModel { | ||
id: Set(1), | ||
name: Set("test".to_string()), | ||
} | ||
.insert(&db.mysql) | ||
.await?; | ||
|
||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; | ||
} | ||
|
||
let _item = product::Entity::find_by_id(1) | ||
.one(&db.readyset) | ||
.await? | ||
.ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; | ||
|
||
let _item = product::Entity::find() | ||
.filter(product::Column::Id.is_in(vec![1, 2, 3])) | ||
.one(&db.readyset) | ||
.await? | ||
.ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; | ||
|
||
let _item = product::Entity::find() | ||
.from_raw_sql(Statement::from_sql_and_values( | ||
DbBackend::MySql, | ||
r#"SELECT * FROM product WHERE id = ?"#, | ||
[1.into()], | ||
)) | ||
.one(&db.readyset) | ||
.await? | ||
.ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; | ||
|
||
let _item = product::Entity::find() | ||
.from_raw_sql(Statement::from_sql_and_values( | ||
DbBackend::MySql, | ||
r#"SELECT * FROM product WHERE id in (1)"#, | ||
[], | ||
)) | ||
.one(&db.readyset) | ||
.await? | ||
.ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; | ||
|
||
#[derive(Debug, FromQueryResult)] | ||
pub struct ProductName { | ||
pub name: String, | ||
} | ||
|
||
let _foo = ProductName::find_by_statement(Statement::from_sql_and_values( | ||
DbBackend::MySql, | ||
r#"SELECT product.name as name from product left join has_decimal on product.id = has_decimal.id where product.id = 1"#, | ||
[], | ||
)) | ||
.one(&db.readyset) | ||
.await? | ||
.ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use app::docker; | ||
use color_eyre::Result; | ||
use entity::view_type; | ||
use sea_orm::ActiveModelTrait; | ||
use sea_orm::Set; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let db = docker::db_connect().await; | ||
|
||
let item = view_type::ActiveModel { | ||
channel_id: Set(1), | ||
view_type: Set("list".to_string()), | ||
enabled: Set(true) | ||
} | ||
.insert(&db.mysql) | ||
.await?; | ||
|
||
println!("item: {:?}", item); | ||
Ok(()) | ||
} |
Oops, something went wrong.