Real-world example desktopcouch application?

22 views
Skip to first unread message

Jonathan Lange

unread,
Jan 1, 2010, 7:06:31 AM1/1/10
to desktop...@googlegroups.com
Hello,

I'm mucking around with desktopcouch at the moment, and I think I'm
reaching the stage where it would really help to look at the code for
a functioning application. Where might I find an example of an app
written particularly for desktopcouch?

Some of the questions on my mind are:
- How to map from desktopcouch records to application-level objects
- How to best work with map & reduce functions, both in terms of
storing them in VC, but also loading them without having 'if
db.view_exists()'-style code everywhere

Bonus points if the app has good unit tests.

I had a quick trawl around the Ubuntu One code I'm allowed to see, and
couldn't find anything that even mentioned desktopcouch (it was a
quick look). I've also had a look at Ryan Paul's branch of GTG that
adds couch support, but that doesn't work, and GTG's design makes it
hard to get answers to those questions.

Thanks,
jml

Chris Anderson

unread,
Jan 1, 2010, 1:37:45 PM1/1/10
to desktop...@googlegroups.com
On Fri, Jan 1, 2010 at 4:06 AM, Jonathan Lange <j...@mumak.net> wrote:
> Hello,
>
> I'm mucking around with desktopcouch at the moment, and I think I'm
> reaching the stage where it would really help to look at the code for
> a functioning application. Where might I find an example of an app
> written particularly for desktopcouch?

I'll second Jonathan's request. I'd enjoy paging through some example
code myself.

Jonathan, have you looked at the Quickly project? https://launchpad.net/quickly

Rumor has it that it'd have the sorts of things you are talking about.

To desktopcouch developers: there are a lot of CouchDB users who are
web-developers. If there was a tutorial like: "So you understand the
web and CouchDB, let's learn desktop programming" I bet it'd get a lot
of play.

I for one haven't the foggiest idea how I'd start writing a desktop
app for Ubuntu, aside from reading the link I posted above.

Chris

>
> Some of the questions on my mind are:
>  - How to map from desktopcouch records to application-level objects
>  - How to best work with map & reduce functions, both in terms of
> storing them in VC, but also loading them without having 'if
> db.view_exists()'-style code everywhere
>
> Bonus points if the app has good unit tests.
>
> I had a quick trawl around the Ubuntu One code I'm allowed to see, and
> couldn't find anything that even mentioned desktopcouch (it was a
> quick look). I've also had a look at Ryan Paul's branch of GTG that
> adds couch support, but that doesn't work, and GTG's design makes it
> hard to get answers to those questions.
>
> Thanks,
> jml
>

> --
>
> You received this message because you are subscribed to the Google Groups "Desktop CouchDB" group.
> To post to this group, send email to desktop...@googlegroups.com.
> To unsubscribe from this group, send email to desktop-couch...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/desktop-couchdb?hl=en.
>
>
>

--
Chris Anderson
http://jchrisa.net
http://couch.io

Jonathan Lange

unread,
Jan 1, 2010, 5:59:32 PM1/1/10
to desktop...@googlegroups.com
On Sat, Jan 2, 2010 at 5:37 AM, Chris Anderson <jch...@apache.org> wrote:
> On Fri, Jan 1, 2010 at 4:06 AM, Jonathan Lange <j...@mumak.net> wrote:
>> Hello,
>>
>> I'm mucking around with desktopcouch at the moment, and I think I'm
>> reaching the stage where it would really help to look at the code for
>> a functioning application. Where might I find an example of an app
>> written particularly for desktopcouch?
>
> I'll second Jonathan's request. I'd enjoy paging through some example
> code myself.
>
> Jonathan, have you looked at the Quickly project? https://launchpad.net/quickly
>

Indeed. I've even submitted patches :)

> Rumor has it that it'd have the sorts of things you are talking about.
>

Not quite. It helps you get started quickly, but it doesn't yet have
things to help you say "I'm going to have a document that looks like
this, go make me some boilerplate".

> To desktopcouch developers: there are a lot of CouchDB users who are
> web-developers. If there was a tutorial like: "So you understand the
> web and CouchDB, let's learn desktop programming" I bet it'd get a lot
> of play.
>
> I for one haven't the foggiest idea how I'd start writing a desktop
> app for Ubuntu, aside from reading the link I posted above.
>

Quickly is a great application for this getting started part. It's the
next part that I need help with.

jml

Stuart Langridge

unread,
Jan 1, 2010, 11:11:45 PM1/1/10
to desktop...@googlegroups.com
On 01/01/2010 12:06 PM, Jonathan Lange wrote:
> I'm mucking around with desktopcouch at the moment, and I think I'm
> reaching the stage where it would really help to look at the code for
> a functioning application. Where might I find an example of an app
> written particularly for desktopcouch?

At the moment, DC is new enough that it's hard to point at such an
application (it was only released two months ago, remember :)) As you
note, the Ubuntu One client does a little DC (when the applet starts up,
it creates a desktopcouch pairing between your machine and Ubuntu One if
you're paired for filesync); see /usr/bin/ubuntuone-client-applet for
that. Ryan's not only worked on desktopcouch in GTG (and written the Ars
article about it, which I imagine you've read: http://arst.ch/b0l if
not) but has also been working on desktopcouch in gwibber, but again I
don't think that's reached public branches yet. Every Quickly app uses
desktopcouch for storing preferences, and can relatively easily also use
the CouchGrid widget for rendering data in a Gtk treeview widget, and
that code might be a place to start.

> - How to best work with map& reduce functions, both in terms of


> storing them in VC, but also loading them without having 'if
> db.view_exists()'-style code everywhere

You've discovered the idea of storing this stuff on the filesystem,
which is The Right Way to do this ;)

sil

Jonathan Lange

unread,
Jan 2, 2010, 12:38:38 AM1/2/10
to desktop...@googlegroups.com
On Sat, Jan 2, 2010 at 3:11 PM, Stuart Langridge
<stuart.l...@canonical.com> wrote:
> On 01/01/2010 12:06 PM, Jonathan Lange wrote:
>> I'm mucking around with desktopcouch at the moment, and I think I'm
>> reaching the stage where it would really help to look at the code for
>> a functioning application. Where might I find an example of an app
>> written particularly for desktopcouch?
>
> At the moment, DC is new enough that it's hard to point at such an
> application (it was only released two months ago, remember :))

Fair enough. In which case, I'll be a little more adventurous and a
little more rigorous about taking notes, asking questions and filing
bugs. :)

jml

Manuel de la Peña

unread,
Jan 2, 2010, 10:43:00 AM1/2/10
to desktop...@googlegroups.com
Hello *,

I´m working on a ODM (Object Document Mapper) that will allow to map  POPO (Plain Old Python Objects) to documents. All the code is based on the work I have been doing in Macaco-contacts and everything I´ve learned when working on it.

The idea is similar to the one used in SQLalchemy where you register a mapping between an object and a document . Once the map is registered the API allowstoperform CRUD operations easily and generates a number of default views to query the DB. My attempt is to simplify applications to use desktopcouch without much problem.

My idea is to realse the code at the begining of Feb (I´m working on it during my holidays). Hopefully the code will work as an example and will allow people to work with the desktopcouch easily.

Kr,

Mandel


2010/1/2 Jonathan Lange <jonatha...@gmail.com>

Jonathan Lange

unread,
Jan 2, 2010, 9:03:44 PM1/2/10
to desktop...@googlegroups.com
2010/1/3 Manuel de la Peña <eti...@gmail.com>:

> Hello *,
>
> I´m working on a ODM (Object Document Mapper) that will allow to map  POPO
> (Plain Old Python Objects) to documents. All the code is based on the work I
> have been doing in Macaco-contacts and everything I´ve learned when working
> on it.
>
> The idea is similar to the one used in SQLalchemy where you register a
> mapping between an object and a document . Once the map is registered the
> API allowstoperform CRUD operations easily and generates a number of default
> views to query the DB. My attempt is to simplify applications to use
> desktopcouch without much problem.
>

Interesting.

One of the things I've discovered in my researches is couchdb.schema,
which looks to be exactly what you describe. Does your work interact
with couchdb.schema at all?

jml

eric casteleijn

unread,
Jan 4, 2010, 10:36:15 AM1/4/10
to desktop...@googlegroups.com
On 01/01/2010 07:06 AM, Jonathan Lange wrote:
> Hello,
>
> I'm mucking around with desktopcouch at the moment, and I think I'm
> reaching the stage where it would really help to look at the code for
> a functioning application. Where might I find an example of an app
> written particularly for desktopcouch?
>
> Some of the questions on my mind are:
> - How to map from desktopcouch records to application-level objects

It perhaps does not have enough signs pointing to it, but there is some
API and documentation for this part included with desktopcouch:

code:

http://bazaar.launchpad.net/~ubuntuone-control-tower/desktopcouch/trunk/annotate/head%3A/desktopcouch/records/field_registry.py

doctest:

http://bazaar.launchpad.net/~ubuntuone-control-tower/desktopcouch/trunk/annotate/head%3A/desktopcouch/records/doc/field_registry.txt

Basically, it provides a relatively simple way to set up mappings
between fields in your application objects, and fields in a desktopcouch
record object.

Please let me know if there are things that are unclear, or
functionality that is missing.

Jonathan Lange

unread,
Jan 4, 2010, 3:47:16 PM1/4/10
to desktop...@googlegroups.com

Thanks. I'll have a play & get back to you.

jml

Manuel de la Peña

unread,
Jan 5, 2010, 5:20:35 AM1/5/10
to desktop...@googlegroups.com
Erinc,

My code is a little bit more complicated since it does not only provide simple mapping from class attribute/property but it adds the following ideas:

  • Dirty objects: The API adds a proxy that will be used to register if a mapped attribute/field has been modified. In that case the proxy will register the changes so that those fields are the only ones to be change when regenereting the document. In order to make the system as fast as possible the lib use a cache (simple dict or memcache) that will store all generated docs and will just update the required fields.
  • Session object: The object takes care of the serialization of the objects. The session keeps track of the object it has related with them. This allows the user to complitelly forget about the changes made and just make him take care of the commit of the session changes. Curretly all the commits are done one by one but this is a limitation from the desktopcouch API which does not have a method similar to update_batch (in python couchdb). This limitations makes very hard to allow transactions but it should be easily solved (Im preaty sure Chad can easily add that method to the API)
Taking into accout the above to points the API I provided offers three different types of objects at runtime (according to their use):

  1. transient: never persistent, not associated with any Session
  2. persistent: associated with a unique Session
  3. detached: previously persistent, not associated with any Session
The mapping are also a little bit more elaborated. An example of a mapping would be the following:

class ContactMapper(ClassMapper):
def __init__(self):
ClassMapper.__init__(self, Contact, ‘contact‘)
self.map(‘first_name‘, ‘name‘)
self.map(‘middle_name‘, ‘mname‘)
self.map(‘last_name‘, ‘surname‘) # can be a property instead of an attribute
self.id(‘id‘) # can be any property no necesarily id
self.init(Contact, -1, ‘‘, ‘‘, ‘‘)
And a group that contains contacts can be mapped in the following way:
class GroupMapped(ClassMapper):
def __init__(self):
ClassMapper.__init__(self, Group, ‘group‘)
self.map(‘name‘, ‘name‘)
# we reference the contact in the group_contacts field
self.references(‘group_contacts‘, ‘contacts‘)

The mappings allow to use more complicated documents to be generated which may contain:
  • Referenced objects: Objects can reference other objects and use a doc design where only the ids are stored in the collection. The mapping can mark such collections as lazy (example self.references(´group_contact´, ´contacts´).lazy() ). This means that when deserialized the proxy provided by the session object uses lazy collections that will retrieve the data of the referenced object only when it is required. 
  • Emebed objects: Allows to design documents where we emeb the document of an object in an other doc. Perfect example of this would be the Contact record in desktopcouch where an address can be an object and it is embeded in the doc.
  • File attachments: Blobs can be added to object as attachments.
  • Constructos are idependent to mappings: If the __init__ methos takes parameters it can be specified in the mapping.
As you might have noticed I´m using a mapping style similar to the one used in FluentNhibernate which means that the mapper at startup is slower but perfoms checks on the maps to ensure that were correctly done ensuring that attributes all required data was provided (id, init etc..) and that only one mapper has been regiatered (easier to debug).

I just started this code to allow me port as many applications as possible to desktopcouch (and fill those empty hours during xmas holidays) and I by no means say it is better in any ground. Nevertheless I´ll release the code in a few week and I´ll be very happy if people take a look into it anduse it. It is a pity I did not know about the ubuntu one code beforehand, but since I have already done the code I thinks is better if a sahre it.

Kr,

Manuel

2010/1/4 eric casteleijn <eric.ca...@canonical.com>
Reply all
Reply to author
Forward
0 new messages