lib/active_document/database.rb in ninjudd-active_document-0.0.3 vs lib/active_document/database.rb in ninjudd-active_document-0.0.4
- old
+ new
@@ -111,15 +111,24 @@
key = Tuple.dump(model.primary_key)
data = Marshal.dump(model)
flags = opts[:create] ? Bdb::DB_NOOVERWRITE : 0
db.put(transaction, key, data, flags)
rescue Bdb::DbError => e
- raise ActiveDocument::DuplicatePrimaryKey, "primary key #{model.primary_key.inspect} already exists"
+ if e.message =~ /DB_KEYEXIST/
+ raise ActiveDocument::DuplicatePrimaryKey, "primary key #{model.primary_key.inspect} already exists"
+ else
+ raise e
+ end
end
def delete(model)
key = Tuple.dump(model.primary_key)
db.del(transaction, key, 0)
+ end
+
+ def truncate
+ # Delete all records in the database. Beware!
+ db.truncate(transaction)
end
def open
if @db.nil?
@db = environment.db