<commit_before>public extension <%= model.name %> {
    var itself: String { get { return "WHERE \(<%= model.name %>.tableName.unwrapped).\("id".unwrapped) = \(id)" } }

    func delete() {
        let deleteSQL = "DELETE FROM \(<%= model.name %>.tableName.unwrapped) \(itself)"
        executeSQL(deleteSQL)
    }

    <% model.properties_exclude_id.each do |property| %>
    <%= """mutating func update(#{property.key} #{property.key}: #{property.type}) -> #{model.name} {
        return self.update([.#{property.key}: #{property.key}])
    }""" %>
    <% end %>

    mutating func update(attributes: [<%= model.name %>.Column: Any]) -> <%= model.name %> {
        var setSQL: [String] = []
        for (key, _) in attributes {
            switch key {
            <% model.properties_exclude_id.each do |property| %>
            <%= """case .#{property.key}: setSQL.append(\"\(key.unwrapped) = \(self.(#{property.key}#{property.is_optional? ? "?" : ""}.unwrapped)\")
            """ %>
            <% end %>
            default: break
            }
        }
        let updateSQL = "UPDATE \(<%= model.name %>.tableName.unwrapped) SET \(setSQL.joinWithSeparator(", ")) \(itself)"
        executeSQL(updateSQL) {
            for (key, value) in attributes {
                switch key {
                <% model.properties_exclude_id.each do |property| %>
                <%= """case .#{property.key}: self.#{property.key} = value as#{property.is_optional? ? "?" : "!"} #{property.type_without_optional}
                """ %>
                <% end %>
                default: break
                }
            }
        }
        return self
    }
}<commit_msg>Add save method to model<commit_after>public extension <%= model.name %> {
    var itself: String { get { return "WHERE \(<%= model.name %>.tableName.unwrapped).\("id".unwrapped) = \(id)" } }

    func delete() {
        let deleteSQL = "DELETE FROM \(<%= model.name %>.tableName.unwrapped) \(itself)"
        executeSQL(deleteSQL)
    }

    <% model.properties_exclude_id.each do |property| %>
    <%= """mutating func update(#{property.key} #{property.key}: #{property.type}) -> #{model.name} {
        return self.update([.#{property.key}: #{property.key}])
    }""" %>
    <% end %>

    mutating func update(attributes: [<%= model.name %>.Column: Any]) -> <%= model.name %> {
        var setSQL: [String] = []
        for (key, _) in attributes {
            switch key {
            <% model.properties_exclude_id.each do |property| %>
            <%= """case .#{property.key}: setSQL.append(\"\(key.unwrapped) = \(self.(#{property.key}#{property.is_optional? ? "?" : ""}.unwrapped)\")
            """ %>
            <% end %>
            default: break
            }
        }
        let updateSQL = "UPDATE \(<%= model.name %>.tableName.unwrapped) SET \(setSQL.joinWithSeparator(", ")) \(itself)"
        executeSQL(updateSQL) {
            for (key, value) in attributes {
                switch key {
                <% model.properties_exclude_id.each do |property| %>
                <%= """case .#{property.key}: self.#{property.key} = value as#{property.is_optional? ? "?" : "!"} #{property.type_without_optional}
                """ %>
                <% end %>
                default: break
                }
            }
        }
        return self
    }
    var save: <%= model.name %> {
        get {
            <%= model.name %>.create(id<%= property_exclude_id_key_value_pairs %>)
            return self
        }
    }
}
{'fraction_non_alphanumeric': 0.1856168277430358, 'fraction_numerical': 0.0, 'mean_word_length': 1.969620253164557, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 40, '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': '2361366', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1032, 'n_words': 197}