def __init__(self, db_file=None): Database._singleton is None or util.throw('database already created! ( %s )' % Database._singleton.db_file) Database._singleton = self if db_file is not None: self.db_fd = None self.db_file = db_file else: self.db_fd, self.db_file = tempfile.mkstemp() print 'db [%s]' % self.db_file if not os.path.exists(os.path.dirname(self.db_file)): print ' (+) dir %s' % os.path.dirname(self.db_file) os.makedirs(os.path.dirname(self.db_file)) self.connection = None self.cursor = None
def retrieve(table, oid): row = table.select('json').where(oid=oid).fetch_one() row is not None or util.throw('unknown oid ( %s )!' % oid) return util.Object(row['json'])
def execute(self): Database.singleton() is not None or util.throw('database not created!') return Database.singleton().execute(self)
def fetch_one(self): Database.singleton() is not None or util.throw('database not created!') return Database.singleton().execute(self).fetch_one(*self.columns)