-
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
- Loading branch information
1 parent
099cc01
commit 25fe95b
Showing
18 changed files
with
860 additions
and
60 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
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
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,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
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 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pub mod has_decimal; | ||
pub mod product; | ||
|
||
pub mod prelude; | ||
pub mod order; |
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,13 @@ | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
#[sea_orm(table_name = "order")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: i32, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation {} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
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 |
---|---|---|
@@ -1,2 +1,12 @@ | ||
pub use super::has_decimal::Entity as HasDecimal; | ||
pub use super::has_decimal::Model as HasDecimalModel; | ||
|
||
pub use super::product::Entity as Product; | ||
pub use super::product::Model as ProductModel; | ||
|
||
pub use super::order::Entity as Order; | ||
pub use super::order::Model as OrderModel; | ||
|
||
pub use sea_orm::QueryOrder; | ||
pub use sea_orm::QuerySelect; | ||
pub use sea_orm::QueryTrait; |
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,14 @@ | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
#[sea_orm(table_name = "product")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: i32, | ||
pub name: String, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation {} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
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