New SqlRoot class
Closed this issue · 3 comments
mbucc commented
Hey, new way works great. Here's what I ended up with. If you like, add it to project. Either way, close ticket. :)
My preferred license is ISC, but I'll leave that to you.
'''
Root object for Prevayler system that includes connection to SQLite.
Mon Sep 26 17:46:59 EDT 2011
'''
import sqlite3
class SqlRoot(dict):
def __init__(self, *args, **kwds):
dict.__init__(self, *args, **kwds)
self.connect()
def __getstate__(self):
value = {
'attributes': self.__dict__,
'dbState' : ";".join(list(self.dbconn.iterdump()))
}
return value
def __setstate__(self, value):
self.__dict__ = value['attributes']
self.connect()
self.dbconn.executescript(value['dbState'])
def connect(self):
# XXX: read up more on sqlite transactions ...
self.dbconn = sqlite3.connect(
':memory:',
detect_types = sqlite3.PARSE_DECLTYPES,
isolation_level = "IMMEDIATE"
)
PetrGlad commented
I better add this to code examples in source since someone else might want to do this differently.
PetrGlad commented
Please review license note. I am not sure if such note should be in every file or one per project is sufficient.
mbucc commented
My personal preference is to put it in every file. But it's just a preference.
What you have is fine.