Introducing the json Attribute Type
I'm happy to present a new type of database attributes: json. It makes storing arbitrary JavaScript objects into the database really seamless. Serialization and deserialization are performed automatically; the API makes it impossible to store an invalid JSON. The type is opaque for database queries: it's just coerced to string.
As always, the main goal was simplicity. Here is an example of an evaluation session:
>>> rv.X.create({j: ['json', {prop: 'value'}]})
>>> rv.X.insert({j: [1, 2, 3]})
>>> rv.X.insert({j: 42})
>>> rv.X.insert({}) // use the default {prop: 'value'}
>>> repr(rv.X.all().get({attr: 'j'}))
[[1, 2, 3], 42, {prop: "value"}]
June 07, 2010 by korenyushkin