<commit_before>import Vapor
import FluentProvider

final class AccessToken: Model {
    let storage = Storage()
    
    let token: String
    let userId: Identifier
    
    static let tokenKey = "token"
    
    init(token: String, userId: Identifier) {
        self.token = token
        self.userId = userId
    }
    
    init(row: Row) throws {
        token = try row.get(AccessToken.tokenKey)
        userId = try row.get(User.foreignIdKey)
    }
    
    func makeRow() throws -> Row {
        var row = Row()
        try row.set(AccessToken.tokenKey, token)
        try row.set(User.foreignIdKey, userId)
        return row
    }
}

extension AccessToken: Preparation {
    static func prepare(_ database: Database) throws {
        try database.create(self) { builder in
            builder.id()
            builder.string(AccessToken.tokenKey)
            builder.parent(User.self)
        }
    }
    
    static func revert(_ database: Database) throws {
        try database.delete(self)
    }
}

extension AccessToken: JSONConvertible {
    convenience init(json: JSON) throws {
        try self.init(
            token: json.get(AccessToken.tokenKey),
            userId: json.get(User.foreignIdKey)
        )
    }
    
    func makeJSON() throws -> JSON {
        var json = JSON()
        try json.set(AccessToken.tokenKey, token)
        return json
    }
}

extension AccessToken: ResponseRepresentable {}

extension AccessToken: Timestampable {}<commit_msg>Added index to token of access_token table<commit_after>import Vapor
import FluentProvider

final class AccessToken: Model {
    let storage = Storage()
    
    let token: String
    let userId: Identifier
    
    static let tokenKey = "token"
    
    init(token: String, userId: Identifier) {
        self.token = token
        self.userId = userId
    }
    
    init(row: Row) throws {
        token = try row.get(AccessToken.tokenKey)
        userId = try row.get(User.foreignIdKey)
    }
    
    func makeRow() throws -> Row {
        var row = Row()
        try row.set(AccessToken.tokenKey, token)
        try row.set(User.foreignIdKey, userId)
        return row
    }
}

extension AccessToken: Preparation {
    static func prepare(_ database: Database) throws {
        try database.create(self) { builder in
            builder.id()
            builder.string(AccessToken.tokenKey)
            builder.parent(User.self, unique: true)
        }
        try database.index(AccessToken.tokenKey, for: AccessToken.self)
    }
    
    static func revert(_ database: Database) throws {
        try database.delete(self)
    }
}

extension AccessToken: JSONConvertible {
    convenience init(json: JSON) throws {
        try self.init(
            token: json.get(AccessToken.tokenKey),
            userId: json.get(User.foreignIdKey)
        )
    }
    
    func makeJSON() throws -> JSON {
        var json = JSON()
        try json.set(AccessToken.tokenKey, token)
        return json
    }
}

extension AccessToken: ResponseRepresentable {}

extension AccessToken: Timestampable {}
{'fraction_non_alphanumeric': 0.08943089430894309, 'fraction_numerical': 0.0, 'mean_word_length': 2.2041666666666666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2538720', 'n_tokens_mistral': 875, 'n_tokens_neox': 878, 'n_words': 228}