vapor/fluent-sqlite-driver

FluentSQLiteDriver cannot read value with type .date

TomShen1234 opened this issue · 1 comments

Steps to reproduce

While working on another project that's using SQLite, I found another issue relating to the .date storage type. It can write to the database just fine, however, when reading the data, the server will return an error.

To reproduce, add a date to the default template app:

final class Todo: Model, Content {
    static let schema = "todos"
    
    @ID(key: .id)
    var id: UUID?

    @Field(key: "title")
    var title: String
    
    @Field(key: "saveDate")
    var date: Date

    init() { }

    init(id: UUID? = nil, title: String, date: Date) {
        self.id = id
        self.title = title
        self.date = date
    }
}

Then in the migration, add the new field with the .date type:

.field("saveDate", .date, .required)

Finally make a POST request with the following data:

{
  "date": "2020-04-03T00:00:00Z",
  "title": "Test"
}

Now when you make a GET request to retrieve the data, it will return an error message (see below) and failed.

Expected behavior

The server should return the saved dates

Actual behavior

This error message is sent to me:

[ ERROR ] invalid field: saveDate type: Date error: typeMismatch(Foundation.Date, Swift.DecodingError.Context(codingPath: [], debugDescription: "Could not initialize Date from 1585872000.", underlyingError: nil))

The .datetime data type works fine without any error.

Environment

  • Vapor Framework version: 4.4.0
  • FluentSQLiteDriver version: 4.0.0-rc1.1
  • OS version: macOS 10.15.4
0xTim commented

Closing in favour of vapor/sqlite-kit#78