SQLInsertBuilder and SQLUpdateBuilder do not expose the ignore flag
0xTim opened this issue · 2 comments
While it is possible to issue an INSERT IGNORE
(or other database equivalent) query at the Fluent level using Model.create(orIgnore:on:)
, it is not possible to issue the same query at the SQL
level using SQLInsertBuilder
- one must build the appropriate SQLInsert
object manually or use a raw query. Once Fluent supports UPDATE IGNORE
, a similar issue will exist for SQLUpdateBuilder
as well. The best API for this is probably a simple public func ignore(_ flag: Bool = true) -> Self
function on both builders.
Looks like the syntax for this varies a bit between SQLs.
- MySQL:
INSERT IGNORE
(https://dev.mysql.com/doc/refman/8.0/en/insert.html) - PostgreSQL:
INSERT ... ON CONFLICT (...) DO NOTHING
(https://www.postgresql.org/docs/10/static/sql-insert.html) - SQLite:
INSERT OR IGNORE
(https://www.sqlite.org/lang_insert.html)
I'm not 100% sure whether that PostgreSQL syntax actually has the same functionality. Either way, this seems like it will need to be added to the DB packages individually similar to the ALTER TABLE
query and other stuff.
Duplicate of #31