Closed MrMage closed 6 years ago
@MrMage sorry this was a bit confusing since the PostgreSQLEnum
type was changed to use native PSQL enums in a previous release. I've added back a PostgreSQLRawEnum
which should give the behavior you are expecting.
Implementing an enum with this protocol looks something like:
enum Availability: UInt8, PostgreSQLRawEnum {
static var allCases: [Availability] = [.everyday, .sunday, .monday, .tuesday, .wednesday, .thursday, .friday, .saturday]
case everyday
case sunday
case monday
case tuesday
case wednesday
case thursday
case friday
case saturday
}
struct Foo: PostgreSQLModel, Migration {
var id: Int?
var availability: Availability
}
In Swift 4.2, you will no longer need to implement allCases
.
Closing this now that we have PostgreSQLRawEnum
. Let me know if that works for you 👍.
Just a quick heads-up that that worked. Thanks, Tanner!
(I am using all relevant packages on the
master
branch.)I have an enum like this:
If I try to make this codable and encoded as an
int8
as follows, usingEntityType
fields in a model creates table columns of typeint8
as expected:However, then I get runtime errors because the enum is not
ReflectionDecodable
. If I addReflectionDecodable
conformance like this:Then my migrations create the column as type
jsonb
instead and I get PostgreSQL errors likecannot compare jsonb = bigint
for query filters like.filter(\MyModelType.entityType == .appActivity)
.How can I ensure that Fluent creates my column of type
.int8
even if conforming to ReflectionDecodable?