Index: library/mongodb/nx-mongo.tcl =================================================================== diff -u -reef878fdd83b2fcf27a2644e6e8788a12f714c26 -rbcf94f0b3bac771ebd9a65a8eb9dd6030651bb7e --- library/mongodb/nx-mongo.tcl (.../nx-mongo.tcl) (revision eef878fdd83b2fcf27a2644e6e8788a12f714c26) +++ library/mongodb/nx-mongo.tcl (.../nx-mongo.tcl) (revision bcf94f0b3bac771ebd9a65a8eb9dd6030651bb7e) @@ -231,9 +231,9 @@ # # For interaction with bson structures, we provide on the class # level "bson query" (a small dsl for a more convenient syntax in - # bson queries) and "bson parameter" which translates from a bson - # structure (tuple) into a dashed parameter list used in object - # creation. + # bson queries), "bson atts (a simplifed attribute selection) and + # "bson parameter" which translates from a bson structure (tuple) + # into a dashed parameter list used in object creation. # :method "bson query" {{-cond ""} {-orderby ""}} { @@ -260,7 +260,18 @@ #puts "Query: $result" return $result } - + + :method "bson atts" {atts} { + set result {} + foreach {att value} $atts { + if {![string is integer -strict $value]} { + error "$atts: $value should be integer" + } + lappend result $att int $value + } + return $result + } + :method "bson parameter" {tuple} { #puts "bson parameter $tuple" set objParams [list] @@ -350,18 +361,21 @@ # :public method "find first" { {-instance ""} + {-atts ""} {-cond ""} {-orderby ""} } { set tuple [lindex [::nx::mongo::db query ${:mongo_ns} \ [:bson query -cond $cond -orderby $orderby] \ + -atts [:bson atts $atts] \ -limit 1] 0] #puts "find first fetched: $tuple" if {$instance ne ""} {set instance [:uplevel [list ::nsf::object::qualify $instance]]} return [:bson create -name $instance $tuple] } :public method "find all" { + {-atts ""} {-cond ""} {-orderby ""} {-limit} @@ -373,6 +387,7 @@ if {[info exists skip]} {lappend opts -skip $skip} set fetched [::nx::mongo::db query ${:mongo_ns} \ [:bson query -cond $cond -orderby $orderby] \ + -atts [:bson atts $atts] \ {*}$opts] puts "[join $fetched \n]" foreach tuple $fetched { @@ -382,6 +397,7 @@ } :public method show { + {-atts ""} {-cond ""} {-orderby ""} {-limit} @@ -393,6 +409,7 @@ if {[info exists skip]} {lappend opts -skip $skip} set fetched [::nx::mongo::db query ${:mongo_ns} \ [:bson query -cond $cond -orderby $orderby] \ + -atts [:bson atts $atts] \ {*}$opts] set tuples [list] foreach tuple $fetched {