vapor-community / postgresql-provider

PostgreSQL Provider for the Vapor web framework.
MIT License
70 stars 19 forks source link

Failed to prepare #9

Closed hyouuu closed 8 years ago

hyouuu commented 8 years ago

Not sure if the issue should belong to provider or driver; I have a Trip model class, and when preparing the console outputs: Preparing Trip Failed to prepare Trip invalidSQL("ERROR: syntax error at or near \"desc\"\nLINE 1: ...RIMARY KEY NOT NULL, title VARCHAR(255) NOT NULL, desc VARCH...\n ^\n")

In main.swift I have:

var drop = Droplet()
drop.middleware.append(sessions)
try drop.addProvider(VaporPostgreSQL.Provider.self)
drop.preparations.append(Post.self)
drop.preparations.append(Trip.self)

And the Trip class:

import Vapor
import Fluent
import Foundation

final class Trip: Model {
    var id: Node?
    var title: String
    var desc: String

    init(title: String, desc: String) {
        self.id = uid().makeNode()
        self.title = title
        self.desc = desc
    }

    init(node: Node, in context: Context) throws {
        id = try node.extract("id")
        title = try node.extract("title")
        desc = try node.extract("desc")
    }

    func makeNode(context: Context) throws -> Node {
        return try Node(node: [
            "id": id,
            "title": title,
            "desc": desc
            ])
    }
}

extension Trip: Preparation {
    static func prepare(_ database: Database) throws {
        try database.create("trips") { trips in
            trips.id()
            trips.string("title")
            trips.string("desc")
        }
    }

    static func revert(_ database: Database) throws {
        //
    }
}
hyouuu commented 8 years ago

So, when I changed desc name to desca it works... Apparently because SQL has this DESC keyword - added a feature request in fluent (https://github.com/vapor/fluent/issues/131) but it might actually should be a feature in each provider? Please advise and close as needed

tanner0101 commented 8 years ago

Good find! Closing this issue in favor of the Fluent issue.