Index: TODO =================================================================== diff -u -rc85ca5808548fc506bfc39600bafb8b11ecfac43 -r8f4ba2af8b01697a3aab727a2794cb3b456d6632 --- TODO (.../TODO) (revision c85ca5808548fc506bfc39600bafb8b11ecfac43) +++ TODO (.../TODO) (revision 8f4ba2af8b01697a3aab727a2794cb3b456d6632) @@ -2612,6 +2612,8 @@ * new method "show" for mongo mapped classes * added two new example files example-nx-reference-many.tcl and example-nx-reference-one.tcl + * replaced "arg" by "type" in spec for mongo attributes to make + spec less stange TODO: Index: library/mongodb/example-nx-bi.tcl =================================================================== diff -u -rfe68b259d9a15328a04a9dc64394dc5ffe5ba5a4 -r8f4ba2af8b01697a3aab727a2794cb3b456d6632 --- library/mongodb/example-nx-bi.tcl (.../example-nx-bi.tcl) (revision fe68b259d9a15328a04a9dc64394dc5ffe5ba5a4) +++ library/mongodb/example-nx-bi.tcl (.../example-nx-bi.tcl) (revision 8f4ba2af8b01697a3aab727a2794cb3b456d6632) @@ -33,9 +33,9 @@ # Make sure, we start always from scratch, so remove everything from # the collection. -nx::mongo::db remove tutorial.comments {} +nx::mongo::db remove tutorial.postings {} -# +###################################################################### # Create the application classes based on the "Business Insider" data # model. Note that instances of the class "Comment" can be embedded in # a posting (attribute "comments") as well as in an comment itself @@ -44,23 +44,21 @@ # "... delete ..." to add values to the attributes). # nx::mongo::Class create Comment { - # This class does not have a :mongo_ns" spec, since it is embedded. - :attribute author:required :attribute comment:required - :attribute replies:embedded,arg=::Comment,0..n {set :incremental 1} + :attribute replies:embedded,type=::Comment,0..n {set :incremental 1} } nx::mongo::Class create Posting { :index tags :attribute title:required :attribute author:required :attribute ts:required - :attribute comments:embedded,arg=::Comment,0..n {set :incremental 1} + :attribute comments:embedded,type=::Comment,0..n {set :incremental 1} :attribute tags:0..n {set :incremental 1} } -# +###################################################################### # Build a composite Posting instance based on the example above. # set p [Posting new -title "Too Big to Fail" -author "John S." \ @@ -137,6 +135,44 @@ # We still have three entries in the database ? {Posting count} 3 -puts stderr [$q bson pp [$q eval {:bson encode}]] +Posting show -puts stderr ====EXIT \ No newline at end of file +puts stderr ====EXIT +###################################################################### +# Output +###################################################################### +# { +# _id: 4daaeb04727b2b1000000000, +# title: {Too Big to Fail}, +# comments: [ { +# author: {Ian White}, +# comment: {Great Article!} }, { +# replies: [ { +# author: {Jane Smith}, +# comment: scalable? } ], +# author: {Joe Smith}, +# comment: {But how fast is it?} } ], +# author: {John S.}, +# ts: {05-Nov-09 10:33}, +# tags: [ finance, economy ] +# }, { +# _id: 4daaeb04727b2b1000000001, +# title: {Too Big to Fail}, +# comments: [ { +# author: {Ian White}, +# comment: {Great Article!} } ], +# author: {John S.}, +# ts: {05-Nov-09 10:33}, +# tags: [ finance, economy ] +# }, { +# _id: 4daaeb04727b2b1000000002, +# title: {Too Big to Fail}, +# comments: [ { +# author: {Ian White}, +# comment: {Great Article!} }, { +# author: {Gustaf N}, +# comment: {This sounds pretty cool} } ], +# author: {John S.}, +# ts: {05-Nov-09 10:33}, +# tags: [ nsf, nx, finance, economy ] +# } \ No newline at end of file Index: library/mongodb/example-nx-reference-many.tcl =================================================================== diff -u -rc85ca5808548fc506bfc39600bafb8b11ecfac43 -r8f4ba2af8b01697a3aab727a2794cb3b456d6632 --- library/mongodb/example-nx-reference-many.tcl (.../example-nx-reference-many.tcl) (revision c85ca5808548fc506bfc39600bafb8b11ecfac43) +++ library/mongodb/example-nx-reference-many.tcl (.../example-nx-reference-many.tcl) (revision 8f4ba2af8b01697a3aab727a2794cb3b456d6632) @@ -70,7 +70,7 @@ } nx::mongo::Class create Group { :attribute name - :attribute members:embedded,arg=::Member,0..n + :attribute members:embedded,type=::Member,0..n } Group insert -name "grp3" \ @@ -96,7 +96,7 @@ } nx::mongo::Class create Group { :attribute name - :attribute members:reference,arg=::Member,0..n + :attribute members:reference,type=::Member,0..n } Group insert -name "grp4" \ @@ -114,6 +114,9 @@ puts stderr "Content of collection groups:" Group show +###################################################################### +# Output +###################################################################### # Content of collection groups: # { # _id: 4daae3e492b5570e00000000, Index: library/mongodb/example-nx-reference-one.tcl =================================================================== diff -u -rc85ca5808548fc506bfc39600bafb8b11ecfac43 -r8f4ba2af8b01697a3aab727a2794cb3b456d6632 --- library/mongodb/example-nx-reference-one.tcl (.../example-nx-reference-one.tcl) (revision c85ca5808548fc506bfc39600bafb8b11ecfac43) +++ library/mongodb/example-nx-reference-one.tcl (.../example-nx-reference-one.tcl) (revision 8f4ba2af8b01697a3aab727a2794cb3b456d6632) @@ -67,7 +67,7 @@ } nx::mongo::Class create Post { :attribute title - :attribute user:embedded,arg=::User + :attribute user:embedded,type=::User } Post insert -title "Hello embedded World" -user [User new -name Smith] @@ -86,7 +86,7 @@ } nx::mongo::Class create Post { :attribute title - :attribute user:reference,arg=::User + :attribute user:reference,type=::User } Post insert -title "Hello referenced World" -user [User new -name Smith] @@ -98,6 +98,10 @@ puts stderr "Content of the collection groups:" Post show +###################################################################### +# Output +###################################################################### + # Content of the collection groups: # { # _id: 4daae48056b77f0e00000000, Index: library/mongodb/nx-mongo.tcl =================================================================== diff -u -rc85ca5808548fc506bfc39600bafb8b11ecfac43 -r8f4ba2af8b01697a3aab727a2794cb3b456d6632 --- library/mongodb/nx-mongo.tcl (.../nx-mongo.tcl) (revision c85ca5808548fc506bfc39600bafb8b11ecfac43) +++ library/mongodb/nx-mongo.tcl (.../nx-mongo.tcl) (revision 8f4ba2af8b01697a3aab727a2794cb3b456d6632) @@ -8,11 +8,14 @@ package provide nx::mongo 0.2 # todo: how to handle multiple connections; currently we have a single, global connection -# todo: make embedded, reference spec nicer # todo: all references are currently auto-fetched. make this optional +# todo: If "emebds" or "references" are used, the object must be of +# the specified classes, no subclasses allowed +# todo: extend the query language syntax, e.g. regexp, ... # todo: handle remove for non-multivalued embedded objects # idea: handle names of nx objects (e.g. attribute like __name) # idea: handle classes von nx objects (e.g. attribute like __class) +# todo: make "embedded", "reference" spec even nicer? namespace eval ::nx::mongo { @@ -307,6 +310,7 @@ # default slot class # :public method attribute {spec {-class ::nx::mongo::Attribute} {initblock ""}} { + regsub -all {,type=} $spec {,arg=} spec next [list $spec -class $class $initblock] }