1. vadimtsushko
  2. mongo-dart

Source

mongo-dart / lib / objectory / ObjectoryDirectConnectionImpl.dart

Diff from to

File lib/objectory/ObjectoryDirectConnectionImpl.dart

  • Ignore whitespace
 Objectory get objectory() => new ObjectorySingleton._singleton();
-class ObjectorySingleton extends ObjectoryBaseImpl{
+abstract class ObjectorySingleton extends ObjectoryBaseImpl{
   static Objectory _objectory;
   ObjectorySingleton._internal();
   factory ObjectorySingleton._singleton(){
   }
   void save(PersistentObject persistentObject){
     db.collection(persistentObject.type).save(persistentObject);
+    persistentObject.id = persistentObject["_id"];
   }
   void remove(PersistentObject persistentObject){
-    db.save(persistentObject);
+    if (persistentObject.id === null){
+      return;
+    }
+    db.collection(persistentObject.type).remove({"_id":persistentObject.id});
   }
-  Future<List<PersistentObject>> find(String className,[Map query]){
+  Future<List<PersistentObject>> find(String className,[Map selector]){
     Completer completer = new Completer();
     List<PersistentObject> result = new List<PersistentObject>();
     db.collection(className)
-      .find(query)
+      .find(selector)
       .each((map){
-        PersistentObject obj = objectory.newInstance(className);
-        obj.map = map;
-        obj.id = map["_id"];
+        PersistentObject obj = objectory.map2Object(className,map);
         result.add(obj);
       }).then((_) => completer.complete(result));
     return completer.future;  
   }
+  Future<PersistentObject> findOne(String className,[Map selector]){
+    Completer completer = new Completer();    
+    db.collection(className)
+      .findOne(selector)
+      .then((map){              
+        PersistentObject obj = objectory.map2Object(className,map);
+        completer.complete(obj);
+      });
+    return completer.future;  
+  }
+  
+  Future<bool> dropDb(){
+    db.drop();
+  }
 }