Commits

Liam Staskawicz committed 0b1f1d6

* update for fantom 1.0.51 changes (new BuildPod format)

Comments (0)

Files changed (7)

 **
 class Build : BuildPod
 {
-  override Void setup()
+  new make()
   {
     podName = "mongo"
+    summary = "Interface to MongoDB (http://www.mongodb.com)"
+    depends = ["sys 1.0", "inet 1.0"]
+    srcDirs = [`fan/`, `fan/bson/`, `fan/gridfs/`, `test/`]
+    docSrc  = true
     version = Version([0, 1])
   }
 }

fan/Collection.fan

   ** fields      Str[]         A List of the field names to return, such that the entire object is not retrieved
   ** <pre
   **
-  Cursor find(Str:Obj? query := [:], Str:Obj? opts := [:])
+  Cursor find(Str:Obj? query := [:], Str:Obj opts := [:])
   {
     return Cursor(this, query, opts)
   }
   ** Find the first match only for the given query.
   ** See `Collection.find` for a description of relevant opts
   **
-  Map? findOne(Str:Obj? query := [:], Str:Obj? opts := [:])
+  Map? findOne(Str:Obj? query := [:], Str:Obj opts := [:])
   {
     opts["batchsize"] = -1 // only return one instance and close the cursor immediately
     return find(query, opts).next
     // todo - read last error in strict mode
   }
   
-  Map update(Map query, Map doc, Bool upsert := false, Bool multi := false, Bool safe := false)
+  Map update(Str:Obj? query, Str:Obj? doc, Bool upsert := false, Bool multi := false, Bool safe := false)
   {
     b := Buf() { endian = Endian.little }
     b.writeI4(0) // reserved
     db.connection.sendMsg(s.out, b.flip, Mongo.OP_DELETE)
     // todo - read last error in strict mode
   }
-  
-  // MapReduceOut mapReduce(Str map, Str reduce, Str outputCollection, Map query)
-  // {
-  //   
-  // }
+
 }
 
 
   new make()
   { 
     this.inc = (idInc.send(null).get(null) as Int).and(0xFFFFFFFF)
-    this.time = DateTime.nowUnique().and(0xFFFFFFFF)
-    this.machine = IpAddr.local().bytes().toDigest("MD5").readS4().and(0xFFFFFFFF)
+    this.time = DateTime.nowUnique.and(0xFFFFFFFF)
+    this.machine = IpAddr.local.bytes.toDigest("MD5").readS4.and(0xFFFFFFFF)
   }
   
   new fromStream(InStream ins)
   {
-    this.time = ins.readS4().and(0xFFFFFFFF)
-    this.machine = ins.readS4().and(0xFFFFFFFF)
-    this.inc = ins.readS4().and(0xFFFFFFFF)
+    this.time = ins.readS4.and(0xFFFFFFFF)
+    this.machine = ins.readS4.and(0xFFFFFFFF)
+    this.inc = ins.readS4.and(0xFFFFFFFF)
   }
   
   new fromStr(Str s)
   {
-    if(!isValid(s))
-      throw Err("invalid ObjectID format")
+    if(!isValid(s)) throw Err("invalid ObjectID format")
       
     this.time = s[0..7].toInt(16).and(0xFFFFFFFF)
     this.machine = s[8..15].toInt(16).and(0xFFFFFFFF)

pod.fan

-////////////////////////////////////////////////////////////////////////////////
-//
-//  Copyright 2010 Liam Staskawicz
-//
-//  Licensed under the Apache License, Version 2.0 (the "License");
-//  you may not use this file except in compliance with the License.
-//  You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-//  Unless required by applicable law or agreed to in writing, software
-//  distributed under the License is distributed on an "AS IS" BASIS,
-//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//  See the License for the specific language governing permissions and
-//  limitations under the License.
-//
-////////////////////////////////////////////////////////////////////////////////
-
-
-**
-** Mongo Driver
-**
-
-@podDepends = [Depend("sys 1.0"), Depend("inet 1.0")]
-@podSrcDirs = [`fan/`, `fan/bson/`, `fan/gridfs/`, `test/`]
-
-pod mongo {}

test/CollectionTest.fan

       elapsed := (Duration.now - start).toMillis().toFloat
       stat := inserts.toFloat/(elapsed/1000f)
       runlens.add(stat)
-      Sys.out.printLine("run ${run}: ${inserts} inserts - ${elapsed} millis (${stat} insert/sec)")
+      echo("run ${run}: ${inserts} inserts - ${elapsed} millis (${stat} insert/sec)")
     }
     sum := runlens.reduce(0f) |Float r, Float v->Float| { return v + r }
-    Sys.out.printLine("average run time - ${(Float)sum/runlens.size.toFloat}")
+    echo("average run time - ${(Float)sum/runlens.size.toFloat}")
     // c.drop
   }
   
     db.setProfilingLevel(proflevel) // reset it
     
     s := db.profilingInfo
-    Sys.out.printLine("profilingInfo - ${s}")
+    echo("profilingInfo - ${s}")
   }
   
   Void testAuthentication()

test/GridFSTest.fan

     data := "allo there"
     f.save(data.in)
     verifyEq(f.size, data.size)
+    verify(f.isValid)
+    
     
     bigfilepath := "/Users/liam/Documents/mtcode/fan/fantomongo/test/Ruckus.mp3"
     bigfile := File(Uri.fromStr(bigfilepath))
     f2 := gfs.createFile("bigfiletest", bigfile.mimeType)
     f2.save(bigfile.in)
     verifyEq(bigfile.size, f2.size)
+    verify(f2.isValid)
     
     c := gfs.fileList
     verifyEq(2, c.count)