我有一个需要 type的Fluent
(支持的)模型,但我只能存储/ 。Postgres
Decimal
.float
.double
// Model
final class Stat: Model, Content, Equatable {
static let schema: String = "stats"
@ID(key: .id)
var id: UUID?
@Field(key: "name")
var name: String
@Field(key: "earned_run_average")
var era: Decimal // <-- CAN'T DO THIS
}
// Migration
struct CreateStatsTable: Migration {
func prepare(on database: Database) -> EventLoopFuture<Void> {
return database.schema(Stats.schema)
.id()
.field("name", .string, .required)
.field("earned_run_average", .decimal/*.decimal TYPE DOES NOT EXIST */, .required)
.create()
}
func revert(on database: Database) -> EventLoopFuture<Void> {
return database.schema(Stats.schema).delete()
}
}
上述带有迁移的模型将失败。如果这不容易实现(就像.string
or一样容易.double
),有没有办法获得类似于 type Decimal
in的行为Fluent
?