vapor/sql-kit

Supressing IF EXIST, since it is not a strict SQL92 phrase

kerusan opened this issue · 2 comments

Code snippet

        try self.db.drop(table: "planets")
            .ifExists()
            .run().wait()

Generates SQL as
DROP TABLE IF EXISTS "planets"

The phrase IF EXISTS is not part of SQL 92, and is not recognized by databases like Frontbase. Some way of suppressing the .ifExists() function would be preferable when using a database that doesn’t support it.

Since all of our other DBs support this, I think this would make sense as a new option on SQLDialect. Maybe something like var supportsDropIfExists: Bool { get } with a default implementation of true.

SQLDropTable could then check to make sure this is true before serializing ifExists here: https://github.com/vapor/sql-kit/blob/master/Sources/SQLKit/Query/SQLDropTable.swift#L21

+1
I agree on that solution, although I think there should be a wider perspective than the three databases Vapor supports today. Vapor is such a good product that sql-kit should be based on the SQL standard rather than these tree DBs, I'd love to see FluentOracle, FluentDB2, FluentIngres, FluentSQLServer etc. With this I don't mean that the defaults needs to conform to the standard since the common standard is a better base for this, but the SQL standard should be supported.