Matheus Cardoso
Matheus Cardoso

Reputation: 308

string primary key with vapor + fluent

I would like to have a table with a string column as a primary key without having to use raw SQL syntax.

Here's my fluent "preparation":

static func prepare(_ database: Database) throws {    
    try database.create("roles") { roles in
        roles.id("name")
        roles.string("readable_name")
    }
}

According to both my tests and the docs, resulting query will be similar to:

CREATE TABLE `roles` (`name` INTEGER PRIMARY KEY NOT NULL, `readable_name` TEXT NOT NULL)

I could not, so far, find a way to have a string (TEXT, VARCHAR, ...) as a primary key without raw SQL syntax and i would like to know whether it's possible to do it or not using the fluent query builder which comes with vapor.

Upvotes: 3

Views: 1307

Answers (1)

tanner0101
tanner0101

Reputation: 4065

Support for ID types besides INT was added in Fluent 2.

https://docs.vapor.codes/2.0/fluent/model/#id-type

Upvotes: 2

Related Questions