Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support date without time #78

Open
Rubenfer opened this issue Apr 7, 2020 · 4 comments
Open

Support date without time #78

Rubenfer opened this issue Apr 7, 2020 · 4 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@Rubenfer
Copy link

Rubenfer commented Apr 7, 2020

Vapor 4 cannot decode dates.

Steps to reproduce

  1. Create an empty project using vapor-beta toolbox and using a SQLite database for testing purposes.

  2. Open Todo.swift file and add a field to store a date

Todo model file looks:

import Fluent
import Vapor

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

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

    init() { }

    init(id: UUID? = nil, title: String, date: Date) {
        self.id = id
        self.title = title
        self.date = date
    }
}
  1. Configure the field on the migration file.
import Fluent

struct CreateTodo: Migration {
    func prepare(on database: Database) -> EventLoopFuture<Void> {
        return database.schema("todos")
            .id()
            .field("title", .string, .required)
            .field("date", .date, .required)
            .create()
    }

    func revert(on database: Database) -> EventLoopFuture<Void> {
        return database.schema("todos").delete()
    }
}
  1. Run the migrations.

  2. Create a new Todo with ISO8601 date.

  3. Try to get the todos. It fails.

Expected behavior

The list of todos is returned.

Actual behavior

[ ERROR ] invalid field: date type: Date error: Decoding error: Value of type 'Date' required for key ''.

Environment

  • Vapor Framework version: 4.0.0-rc.3.12
  • Fluent Framework version: 4.0.0-rc.1
  • Fluent-kit Framework version: 4.0.0-rc.1.16
  • Fluent-sqlite-driver Framework version: 4.0.0-rc.1.1
  • OS version: macOS 10.15.4
@0xTim
Copy link
Member

0xTim commented Apr 7, 2020

Looks like an SQLite error, this works fine with Postgres

@Rubenfer
Copy link
Author

Rubenfer commented Apr 7, 2020

Yes, I have other projects with Postgres and it works, but today I've tried in a SQLite project just for a quick test and it fails. This is not a critial bug for productions environmets but good to know.

@0xTim
Copy link
Member

0xTim commented Apr 7, 2020

As a temporary workaround, if you change the migration type to .datetime, this then works

@tanner0101 tanner0101 transferred this issue from vapor/vapor Apr 9, 2020
@tanner0101 tanner0101 added the bug Something isn't working label Apr 16, 2020
@tanner0101 tanner0101 changed the title Date decoding bug Support date without time Jul 16, 2020
@tanner0101 tanner0101 added the enhancement New feature or request label Jul 16, 2020
@tanner0101
Copy link
Member

tanner0101 commented Jul 16, 2020

SQLite currently only supports storing Date in the .datetime data type. I've updated this issue to be a feature request for date without time support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants