Hi guys!
How are you?
I haven't written for a while because I have been busy.
I have played
around with the ViewDefinition class because I want to improve it, i
think that the class is poor in functionallity and should be refactored.
I
have tried to replace the ViewDefinition with a DocumentDesign class
and his attributes like objects( view objects, reduce objects, etc), the
next examples should show the features.
server = Server("
http://localhost:5984")
db = server["python.tests"]
v_d_f = ValidateFunction("test", "function(doc){...}", language="javascript")
all = View("all", "function(doc){...}", language="javascript")
by_name = View("by_name", "function(doc){...}", language="javascript")
views = (all, by_name)
#Create the design document
desing_doc = DesignDocument("_design/tests", validate_doc_fun=v_d_f, views=views)
#Commit!!
design_doc.sync(db)
------------
server = Server("
http://localhost:5984")
db = server["python.tests"]
#Get a design document which is already in the db
design_doc = db.get("_design/tests")
#Create 2 views
only_users = View("only_users", "function(doc){...}", reduce_func=None, language="javascript")
only_admins = View("only_admins", "function(doc){...}", reduce_fun=None, language="javascript")
new_views = (only_users, only_admins)
#Add the views to the existing design document.
design_doc.add_views( new_views )
#Commit!!
design_doc.sync(db)
that is all, I hope you could understand my idea and want to hear your comments and suggestions about it.
I could finish the implementation if you think that is needed!
Cheers,
Martin