include/query_buffer.rb in baza-0.0.4 vs include/query_buffer.rb in baza-0.0.5

- old
+ new

@@ -45,28 +45,27 @@ #===Example # buffer.update(:users, {:name => "Kasper"}, {:id => 5}) def update(table, update, terms) STDOUT.puts "Update called on table #{table}." if @debug self.query(@args[:db].update(table, update, terms, :return_sql => true)) + self.flush if @queries_count >= 1000 + return nil end #Shortcut to doing upsert through the buffer instead of through the db-object with the buffer as an argument. #===Example # buffer.upsert(:users, {:id => 5}, {:name => "Kasper"}) def upsert(table, data, terms) @args[:db].upsert(table, data, terms, :buffer => self) + self.flush if @queries_count >= 1000 + return nil end #Plans to inset a hash into a table. It will only be inserted when flush is called. #===Examples # buffer.insert(:users, {:name => "John Doe"}) def insert(table, data) - @lock.synchronize do - @inserts[table] = [] if !@inserts.key?(table) - @inserts[table] << data - @queries_count += 1 - end - + self.query(@args[:db].insert(table, data, :return_sql => true)) self.flush if @queries_count >= 1000 return nil end #Flushes all queries out in a transaction. This will automatically be called for every 1000 queries. \ No newline at end of file