When a ormx::Table does not have any fields marked as default, it would generate a SQL insert statement with a RETURNING clause that does not have any arguments. This results in a database error.
error: error returned from database: syntax error at end of input
--> src/domain.rs:113:31
|
113 | #[derive(Debug, SimpleObject, ormx::Table)]
| ^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
Database logs:
2021-07-22 20:14:16.009 UTC [57] ERROR: syntax error at end of input at character 152
2021-07-22 20:14:16.009 UTC [57] STATEMENT: INSERT INTO addresses (id, address_line1, address_line2, city, province_code, country_code, postal_code) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING
Solution
When ormx table has no default fields:
Omit the RETURNING clause
Use sqlx's execute function instead of fetch_one (as the latter expects atleast one returning value)
Ah, yes! This is still here because, in an earlier version, ormx was designed for tables with database-generated IDs, so there was always at least one generated column.
Great work, thanks!
Problem
When a
ormx::Table
does not have any fields marked asdefault
, it would generate a SQL insert statement with aRETURNING
clause that does not have any arguments. This results in a database error.Example
Database logs:
Solution
When ormx table has no default fields:
RETURNING
clauseexecute
function instead offetch_one
(as the latter expects atleast one returning value)