users = [User.new(name: "John"), User.new(name: "Jake")]
users.insert == Onyx::SQL::BulkQuery(User).new.insert(users)
users.insert.build == {"INSERT INTO users (name) VALUES (?), (?)", ["John", "Jake"]}
users.delete.build == {"DELETE FROM users WHERE id IN (?, ?)", [1, 2]}
This would require patching Enumerable like this:
module Enumerable(T)
def insert
{% if T < Onyx::SQL::Model %}
Onyx::SQL::BulkQuery(T).new.insert(self)
{% else %}
{% raise "Can only call argless Enumerable#insert on Enumerable(Onyx::SQL::Model)" %}
{% end %}
end
end
Which should work fine as Enumerable doesn't have #insert and #delete methods at all and other types like Array do not have these methods with zero arity.
This would require patching
Enumerable
like this:Which should work fine as
Enumerable
doesn't have#insert
and#delete
methods at all and other types likeArray
do not have these methods with zero arity.