Skip to content

Commit

Permalink
Fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Jul 13, 2023
1 parent dfd086f commit 78ed2cd
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions examples/sqlx_sqlite/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use sea_query::{ColumnDef, Expr, Func, Iden, OnConflict, Order, Query, SqliteQue
use sea_query_binder::SqlxBinder;
use serde_json::{json, Value as Json};
use sqlx::{Row, SqlitePool};
use std::ops::DerefMut;
use time::{
macros::{date, time},
PrimitiveDateTime,
Expand Down Expand Up @@ -32,7 +31,7 @@ async fn main() {
.col(ColumnDef::new(Character::Created).date_time())
.build(SqliteQueryBuilder);

let result = sqlx::query(&sql).execute(pool.deref_mut()).await;
let result = sqlx::query(&sql).execute(&pool).await;
println!("Create table character: {result:?}\n");

// Create
Expand Down Expand Up @@ -72,10 +71,7 @@ async fn main() {
.build_sqlx(SqliteQueryBuilder);

//TODO: Implement RETURNING (returning_col) for the Sqlite driver.
let row = sqlx::query_with(&sql, values)
.execute(pool.deref_mut())
.await
.unwrap();
let row = sqlx::query_with(&sql, values).execute(&pool).await.unwrap();

let id: i64 = row.last_insert_rowid();
println!("Insert into character: last_insert_id = {id}\n");
Expand All @@ -96,7 +92,7 @@ async fn main() {
.build_sqlx(SqliteQueryBuilder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values.clone())
.fetch_all(pool.deref_mut())
.fetch_all(&pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -106,7 +102,7 @@ async fn main() {
println!();

let rows = sqlx::query_as_with::<_, CharacterStructTime, _>(&sql, values.clone())
.fetch_all(pool.deref_mut())
.fetch_all(&pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -122,9 +118,7 @@ async fn main() {
.and_where(Expr::col(Character::Id).eq(id))
.build_sqlx(SqliteQueryBuilder);

let result = sqlx::query_with(&sql, values)
.execute(pool.deref_mut())
.await;
let result = sqlx::query_with(&sql, values).execute(&pool).await;
println!("Update character: {result:?}\n");

// Read
Expand All @@ -143,15 +137,15 @@ async fn main() {
.build_sqlx(SqliteQueryBuilder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values.clone())
.fetch_all(pool.deref_mut())
.fetch_all(&pool)
.await
.unwrap();
println!("Select one from character:");
for row in rows.iter() {
println!("{row:?}\n");
}
let rows = sqlx::query_as_with::<_, CharacterStructTime, _>(&sql, values.clone())
.fetch_all(pool.deref_mut())
.fetch_all(&pool)
.await
.unwrap();
println!("Select one from character:");
Expand All @@ -167,7 +161,7 @@ async fn main() {
.build_sqlx(SqliteQueryBuilder);

let row = sqlx::query_with(&sql, values)
.fetch_one(pool.deref_mut())
.fetch_one(&pool)
.await
.unwrap();

Expand All @@ -187,9 +181,7 @@ async fn main() {
)
.build_sqlx(SqliteQueryBuilder);

let result = sqlx::query_with(&sql, values)
.execute(pool.deref_mut())
.await;
let result = sqlx::query_with(&sql, values).execute(&pool).await;
println!("Insert into character (with upsert): {result:?}\n");

// Read
Expand All @@ -207,7 +199,7 @@ async fn main() {
.build_sqlx(SqliteQueryBuilder);

let rows = sqlx::query_as_with::<_, CharacterStructChrono, _>(&sql, values.clone())
.fetch_all(pool.deref_mut())
.fetch_all(&pool)
.await
.unwrap();
println!("Select all characters:");
Expand All @@ -216,7 +208,7 @@ async fn main() {
}

let rows = sqlx::query_as_with::<_, CharacterStructTime, _>(&sql, values.clone())
.fetch_all(pool.deref_mut())
.fetch_all(&pool)
.await
.unwrap();
println!("Select all characters:");
Expand All @@ -231,9 +223,7 @@ async fn main() {
.and_where(Expr::col(Character::Id).eq(id))
.build_sqlx(SqliteQueryBuilder);

let result = sqlx::query_with(&sql, values)
.execute(pool.deref_mut())
.await;
let result = sqlx::query_with(&sql, values).execute(&pool).await;

println!("Delete character: {result:?}");
}
Expand Down

0 comments on commit 78ed2cd

Please sign in to comment.