use crate::core::QueryError;
#[derive(Debug, thiserror::Error)]
pub enum SqlError {
#[error("`Op::In` requires `SqlValue::List`")]
InRequiresList,
#[error("`Op::IsNull` requires `SqlValue::Bool` (true = IS NULL, false = IS NOT NULL)")]
IsNullRequiresBool,
#[error("`Op::Between` requires `SqlValue::List([lo, hi])` with exactly two elements")]
BetweenRequiresTwoElementList,
#[error("`Op::JsonHasKey` requires `SqlValue::String`")]
JsonKeyRequiresString,
#[error("`Op::JsonHasAnyKey` / `Op::JsonHasAllKeys` require `SqlValue::List` of strings")]
JsonKeysRequiresList,
#[error("`Op::JsonContains` / `Op::JsonContainedBy` require `SqlValue::Json`")]
JsonOpRequiresJson,
#[error("bulk UPDATE requires a primary key on the model")]
MissingPrimaryKey,
#[error("empty `IN` list is not supported")]
EmptyInList,
#[error("INSERT requires at least one column")]
EmptyInsert,
#[error("INSERT columns ({columns}) and values ({values}) length mismatch")]
InsertShapeMismatch { columns: usize, values: usize },
#[error("UPDATE requires at least one assignment in `set`")]
EmptyUpdateSet,
#[error("bulk INSERT requires at least one row")]
EmptyBulkInsert,
#[error("bulk INSERT requires every row's `Auto<T>` PKs to agree on Set vs Unset; mixed Set/Unset is not supported")]
BulkAutoMixed,
#[error("bulk INSERT RETURNING returned {actual} rows but {expected} were inserted")]
BulkInsertReturningMismatch { expected: usize, actual: usize },
#[error("`WhereExpr::Or` with an empty branch list matches no rows; was that intentional?")]
EmptyOrBranch,
}
#[derive(Debug, thiserror::Error)]
pub enum ExecError {
#[error(transparent)]
Query(#[from] QueryError),
#[error(transparent)]
Sql(#[from] SqlError),
#[error(transparent)]
Driver(#[from] sqlx::Error),
#[error("`insert_returning` requires `query.returning` to be non-empty; use `insert` instead")]
EmptyReturning,
#[error("foreign-key target `{table}` has no row with primary key {pk}")]
ForeignKeyTargetMissing {
table: &'static str,
pk: i64,
},
#[error("model `{table}` has no `#[rustango(primary_key)]` field — required for FK lookup")]
MissingPrimaryKey {
table: &'static str,
},
}