Now I know what you are thinking. I think. Well, that is my theory and it is
mine and I own that theory. My theory is that you are thinking:
While object databases are not exactly in commonplace use by the IT industry,
within the Python community, there is a long history of kinship with object
databases with ZODB, the Zope Object Database, arguably being the most well
known example.
QP and Durus provide the facility to work directly with the Durus object
database directly. Lets fire up an interactive session to show Durus basics.
% qp -i blog
Profile, connection, publisher, root, sessions, site, users
->>
Working within the interactive session: Pyrepl provides very useful
search and command history capabilities. Control-P and Control-N step through
previous lines entered. Control-R starts up reverse history search - start
typing an entry you've made previously (searches substrings within) and
Control-R again to step through the hits, if any.
Term expansion is perhaps my favorite Pyrepl enhancement - it certainly is
the one that gets used enough. Try it now by entering in a couple letters:
->> pu
And press Tab - you'll be rewarded with either publisher or a list of
terms in the namespace which match the letters entered so far. A real
timesaver.
Access to objects: The interactive session provides us with access to QP
objects (connection, site, publisher), application objects (sessions, users),
a Profile testing class, but the most relevant to our discussion right now is
root.
By convention our application data lives under root, which is itself a
persistent object. Changes to root will persist from session to session
provided a call to connection.commit() has been made to commit the changes
to the database. Lets do some simple examples.
->> from durus.persistent_dict import PersistentDict
->> mydict = PersistentDict()
->> root['test'] = mydict
->> connection.commit()
->>
%
Control-D exits the interactive session, as it also exits a standard Python
interpreter. Restart the interpreter to see if our object was 'saved' or
persisted.
% qp -i blog
Profile, connection, publisher, root, sessions, site, test, users
->>
Very good, test, now shows up in our display -- objects living at the
root level are conveniently displayed as a reminder when we fire up an
interactive session. Lets put some data in test, but first, what was test?
->> test
<PersistentDict 17020>
->> test.items()
[]
Right, now I remember. Ok, add some data.
->> test[1] = 'My first persistent data'
->> connection.commit()
->>
Control-D to quit, and restart again to satisfy any fears that you may have
about your important data.
% qp -i blog
Profile, connection, journals, publisher, root, sessions, site, test, users
->> test.items()
[(1, 'My first persistent data')]
->>
By now you can see that what we are doing is using Python to manage our data,
and, by virtue of subclassing one of Durus persistent object classes, we can
make our Python objects full partners in the Durus object database.
Durus is the database you already know. No object relational mappers to learn,
no SQL to learn or work around.