<commit_before>import Vapor
import Fluent

// MARK: Model

struct Product: Model {
    var id: Node?

    var name: String?
    var code: String?
    var image: String?

    // used by fluent internally
    var exists: Bool = false
}

// MARK: NodeConvertible

extension Product: NodeConvertible {
    init(node: Node, in context: Context) throws {
        id = node["id"]
        name = node["name"]?.string
        code = node["code"]?.string
        image = node["image"]?.string
    }

    func makeNode(context: Context) throws -> Node {
        // model won't always have value to allow proper merges,
        // database defaults to false
        return try Node.init(node:
            [
                "id": id,
                "name": name,
                "code": code,
                "image": image
            ]
        )
    }
}

// MARK: Database Preparations

extension Product: Preparation {
    static func prepare(_ database: Database) throws {
        try database.create("products") { users in
            users.id()
            users.string("name", optional: true)
            users.string("code")
            users.string("image", optional: true)
        }
    }

    static func revert(_ database: Database) throws {
        fatalError("unimplemented \(#function)")
    }
}

// MARK: Merge

extension Product {
    mutating func merge(updates: Product) {
        id = updates.id ?? id
        code = updates.code ?? code
        name = updates.name ?? name
        image = updates.image ?? image
    }
}<commit_msg>first commit<commit_after>import Vapor
import Fluent

// MARK: Model

struct Product: Model {
    var id: Node?

    var name: String?
    var description: String?
    var price: Double?
	  var count: Int?
	  var image_url_1: String?
	  var image_url_2: String?

    // used by fluent internally
    var exists: Bool = false
}

// MARK: NodeConvertible

extension Product: NodeConvertible {
    init(node: Node, in context: Context) throws {
        id = node["id"]
        name = node["name"]?.string
        description = node["image"]?.string
        price = node["price"]?.double ?? 0
    	  count = node["count"]?.int ?? 0
    	  image_url_1 = node["image_url_1"]?.string
    	  image_url_2 = node["image_url_2"]?.string
    }

    func makeNode(context: Context) throws -> Node {
        // model won't always have value to allow proper merges,
        // database defaults to false
        return try Node.init(node:
            [
                "id": id,
                "name": name,
                "description" : description,
                "price" : price,
            	  "count" : count,
            	  "image_url_1" : image_url_1,
            	  "image_url_2" : image_url_2

            ]
        )
    }
}

// MARK: Database Preparations

extension Product: Preparation {
    static func prepare(_ database: Database) throws {
        try database.create("products") { users in
            users.id()
            users.string("name")
            users.string("description")
            users.double("price")
            users.int("count")
            users.string("image_url_1")
            users.string("image_url_2")
        }
    }

    static func revert(_ database: Database) throws {
        fatalError("unimplemented \(#function)")
    }
}

// MARK: Merge

extension Product {
    mutating func merge(updates: Product) {
        id = updates.id ?? id
        name = updates.name ?? name
        description = updates.description ?? description
        price = updates.price ?? price
        count = updates.count ?? count
        image_url_1 = updates.image_url_1 ?? image_url_1
        image_url_2 = updates.image_url_2 ?? image_url_2
    }
}
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.005393743257820928, 'mean_word_length': 1.9436507936507936, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, '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': '2246938', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1036, 'n_words': 290}