lib/mini_sql/builder.rb in mini_sql-0.1.2 vs lib/mini_sql/builder.rb in mini_sql-0.1.3

- old
+ new

@@ -1,16 +1,17 @@ class MiniSql::Builder def initialize(connection, template) - @args = {} + @args = nil @sql = template @sections = {} @connection = connection end [:set, :where2, :where, :order_by, :limit, :left_join, :join, :offset, :select].each do |k| define_method k do |data, args = {}| + @args ||= {} @args.merge!(args) @sections[k] ||= [] @sections[k] << data self end @@ -48,18 +49,18 @@ def query(args = nil) if args @args.merge!(args) end sql = to_sql - @connection.query(sql, args) + @connection.query(sql, @args) end def exec(args = nil) if args @args.merge!(args) end sql = to_sql - @connection.query(sql, args) + @connection.exec(sql, @args) end end