feat: deprecate create_or_update in favour of upsert

The `create_or_update` method has been deprecated and replaced by
`upsert` for clarity and consistency with common database terminology.

This commit also removes the file `src/entity.rs` which has been
forgotten in earlier commits and was no longer part of Georm.
This commit is contained in:
2025-08-09 15:09:22 +02:00
parent 49c7d86102
commit 5d8a1b1917
10 changed files with 25 additions and 100 deletions

View File

@@ -36,7 +36,7 @@ fn composite_key_get_id() {
}
#[sqlx::test(fixtures("composite_key"))]
async fn composite_key_create_or_update(pool: sqlx::PgPool) -> sqlx::Result<()> {
async fn composite_key_upsert(pool: sqlx::PgPool) -> sqlx::Result<()> {
let new_user_role = UserRole {
user_id: 5,
role_id: 2,
@@ -44,7 +44,7 @@ async fn composite_key_create_or_update(pool: sqlx::PgPool) -> sqlx::Result<()>
};
// This will test the upsert query generation bug
let result = new_user_role.create_or_update(&pool).await?;
let result = new_user_role.upsert(&pool).await?;
assert_eq!(5, result.user_id);
assert_eq!(2, result.role_id);

View File

@@ -52,7 +52,7 @@ async fn upsert_handles_generated_fields(pool: sqlx::PgPool) -> sqlx::Result<()>
let mut modified_product = product.clone();
modified_product.price = BigDecimal::from(1200);
let upserted = modified_product.create_or_update(&pool).await?;
let upserted = modified_product.upsert(&pool).await?;
// price is updated
assert_eq!(upserted.price, BigDecimal::from(1200));

View File

@@ -115,7 +115,7 @@ async fn should_create_if_does_not_exist(pool: sqlx::PgPool) -> sqlx::Result<()>
name: "Miura Kentaro".into(),
..Default::default()
};
author.create_or_update(&pool).await?;
author.upsert(&pool).await?;
let all_authors = Author::find_all(&pool).await?;
assert_eq!(1, all_authors.len());
Ok(())
@@ -130,7 +130,7 @@ async fn should_update_if_exist(pool: sqlx::PgPool) -> sqlx::Result<()> {
name: "Miura Kentaro".into(),
..Default::default()
};
author.create_or_update(&pool).await?;
author.upsert(&pool).await?;
let mut all_authors = Author::find_all(&pool).await?;
all_authors.sort();
assert_eq!(3, all_authors.len());