SKITSANOS FOR RIA

Skitsanos

Saturday, September 11, 2010

WDK.API.CouchDb for upcoming SiteAdmin CMS

SiteAdmin CMS on CouchDBAs you probably heard already about our plans to drop completely support for SQL Server and run away from from this ugly monster, so after all we decided to move new SiteAdmin CMS build entirely on Apache CouchDB (http://couchdb.apache.org/ for more details). CouchDB has too many benefits to ignore, plus for content management i i couldn’t think of better option for the moment. for past few years SiteAdmin CMS content objects were serialized into XML and stored into XML fields in SQL Server, which is not exactly the best way of doing things.

So, in order to move existing content objects into CouchDB we actually needed some database client that allows us to connect to CouchDb and do the job quickly without overloading us and our users with complex syntax. Initially i went through bunch of .NET implementations of CouchDB clients, like Divan, SharpCouch and God knows what else it was, yea some of them were quite interesting and complete, but problem mainly with them that they are too complex. (Come on guys why you have to write things in ugly ways? Just because you learned some how-to-be-MVP bullshit in a book last night or been sitting you ass down in university for 5 years and had nothing better to do? What about keeping thing just simple?)

As i was saying, we need something simple that does the job right and quickly, so here we go: WDK. API.CouchDb library for SiteAdmin CMS (well, actually you can use it outside of SiteAdmin CMS, as any other libraries from Skitsanos WDK.* set).

Some of the features available at this moment:

  • Get database server version;
  • Get list of databases
  • Check if database exists
  • Create database
  • Count documents in database
  • Get documents
  • Create document
  • Create design document
  • Get document by ID
  • Get design view
  • Delete document

Couple of code examples in VB.NET:

Dim db As New WDK.API.CouchDb("localhost", 5984)

'- get database server version 
Debug.WriteLine(db.Version)

Dim dbs As List(Of String) = db.getDatabases 
Debug.WriteLine(dbs.Count)

'- Get list of databases 
db.getDatabases()

'- Check if database exists
Debug.WriteLine(db.databaseExists("siteadmincms2"))

'- Create a Database 
db.createDatabase("siteadmincms")

'- Count documents in the database 
db.countDocuments("siteadmincms")

'- Get All documents 
Dim docs As List(Of DocumentInfo) = db.getAllDocuments("siteadmincms")

'- create document 
Dim entry As New LogEntryType 
entry.content = "testing... (" + Now.ToString + ")" 
db.createDocument("siteadmincms", entry)

'- create design document 
db.createDesignDocument("siteadmincms", "ApplicationLog", "showAll", "function(doc){if (doc.type && doc.type == 'LogEntryType') emit(doc.createdOn, doc);}")

'- Get document by ID 
Debug.WriteLine(db.getDocumentAsJson("siteadmincms", "_design/ApplicationLog")) 
Debug.WriteLine(db.getDocumentAsJson("siteadmincms", "4ac4e0e0f94b1e73e40403d1b3008628")) 
Dim entry As LogEntryType = db.getDocument(Of LogEntryType)("siteadmincms", "4ac4e0e0f94b1e73e40403d1b3008628") 
Debug.WriteLine(entry.content)

'- delete document by id 
db.deleteDocument("siteadmincms", "4ac4e0e0f94b1e73e40403d1b3008628")

'-get all documents via design view 
Dim di As Object = db.getDesignView(Of LogEntryType)("siteadmincms", "ApplicationLog", "showAll")

Hope this help you anyhow.

0 comments:

Webware development dedicated blog by Skitsanos R&D Labs. ASP.NET, XML, RIA, Adobe Flex, ActionScript 3, AIR, AJAX, Web 2.0, Backbase, CGI development with RealBasic and other web development issues.
News
Downloads