lib/mosql/sql.rb in mosql-0.1.0 vs lib/mosql/sql.rb in mosql-0.1.1

- old
+ new

@@ -23,15 +23,25 @@ def table_for_ns(ns) @db[@schema.table_for_ns(ns).intern] end + def upsert_ns(ns, obj) h = {} cols = @schema.all_columns(@schema.find_ns(ns)) row = @schema.transform(ns, obj) cols.zip(row).each { |k,v| h[k] = v } upsert(table_for_ns(ns), h) + end + + # obj must contain an _id field. All other fields will be ignored. + def delete_ns(ns, obj) + cols = @schema.all_columns(@schema.find_ns(ns)) + row = @schema.transform(ns, obj) + sqlid = row[cols.index("_id")] + raise "No _id found in transform of #{obj}" if sqlid.nil? + table_for_ns(ns).where(:_id => sqlid).delete end def upsert(table, item) begin upsert!(table, item)