Permalink
Browse files

/

  • Loading branch information...
1 parent b80f605 commit 31b824bc61c6faf33f3f39edd950ad9c9eb69264 billy committed Oct 22, 2009
Showing with 58 additions and 4 deletions.
  1. +9 −3 part2/ExpressionBuilder.cfc
  2. +44 −0 part2/ExpressionBuilderTest.cfc
  3. +5 −1 part2/MongoDBTest.cfc
@@ -64,7 +64,8 @@ function builder(){
}
function start(){
- return builder.start();
+ builder.start();
+ return this;
}
function get(){
@@ -73,9 +74,13 @@ function get(){
//May need at least some exception handling
+function where( js_expression ){
+ builder.add( '$where', js_expression );
+}
-function $tags(val){
- builder.add( 'TAGS', val );
+function inArray(element, val){
+ builder.add( element, val );
+ return this;
}
//vals should be list or array
@@ -92,6 +97,7 @@ function $nin(element,vals){
function $eq(element,val){
builder.add( element, val );
+ return this;
}
@@ -5,7 +5,51 @@
key_exp = {AUTHOR=1,TITLE=1,TS=1};
keys = createObject('java', 'com.mongodb.BasicDBObject').init(key_exp);
+
+
+function $testFluentChain(){
+ criteria = builder.start().
+ inArray( 'TAGS', 'Java' ).
+ $nin( 'AUTHOR', ['bill_1','bill_202','bill_101','bill_999','bogus_bill','bill_506'] ).
+ exists('BODY' , 'orci').
+ get();
+
+ q = createObject('java', 'com.mongodb.BasicDBObject').init(criteria);
+ debug(q);
+ items = coll.find(q,keys);
+ debug(items.count());
+ debug(items.toArray().toString());
+}
+
+
+function $testWhereJSExpression(){
+ builder.start();
+ temp = builder.where( "this.TAGS == 'Java'");
+ q = createObject('java', 'com.mongodb.BasicDBObject').init(builder.get());
+ debug(q);
+ items = coll.find(q,keys);
+ ia = items.toArray();
+ debug(items.count());
+ debug(items.toArray().toString());
+ assertEquals( 7, items.count() );
+}
+
+
+
//array tests: search tags:
+function $testInArray(){
+ builder.start();
+ temp = builder.inArray( 'TAGS', 'Java' );
+ q = createObject('java', 'com.mongodb.BasicDBObject').init(builder.get());
+ debug(q);
+ items = coll.find(q,keys);
+ ia = items.toArray();
+ debug(items.count());
+ debug(items.toArray().toString());
+ assertEquals( 69 , items.count() );
+}
+
+
function testNIN(){
builder.start();
temp = builder.$nin( 'AUTHOR', ['bill_1','bill_202','bill_101','bill_999','bogus_bill'] );
View
@@ -160,7 +160,7 @@
function genDataTest(){
- // genBlogData() ;
+ //genBlogData() ;
}
@@ -190,7 +190,11 @@
mongo.getCollection('blog');
for(i; i < 1000;i++){
createObject('java','java.util.Collections').shuffle(tags);
+ r1 = randrange(1,max);
+ r2 = randrange(r1,max)
newTags = shuffled.subList(r1,r2);
+ //createObject('java','java.util.Collections').shuffle(newTags);
+
entry.title = 'Blog Title No.' & i;
entry.author = 'bill_' & i;
entry.tags = newTags;

0 comments on commit 31b824b

Please sign in to comment.