Skip to content

馃獨 Implement `KeypathEncodable`

Pre-release
Pre-release

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 09 May 00:24
· 186 commits to master since this release
2ffcc11

In case if you use @column names with underscores but variable names are in camelCase you may experience problems when while encoding fetched data you're getting names with underscores.

To solve this problem now we have KeyPathEncodable protocol.

Simply conform your table to KeyPathEncodable and it will always be encoded with property names the same as variable names declared in your model.

Examples

To get as-is

final class User: Table {
    @Column("id")
    var id: Int
    
    @Column("first_name")
    var firstName: String
}

this will be encoded as

{
    "id": 1,
    "first_name": "John"
}

To get with variable names

final class User: Table, KeyPathEncodable {
    @Column("id")
    var id: Int
    
    @Column("first_name")
    var firstName: String
}

this will be encoded as

{
    "id": 1,
    "firstName": "John"
}