本文整理汇总了Python中CodernityDB.database.Database类的典型用法代码示例。如果您正苦于以下问题:Python Database类的具体用法?Python Database怎么用?Python Database使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BenchCodernityDB
class BenchCodernityDB(BenchBase):
ID_FIELD = "_id"
def __init__(self, *args, **kwargs):
super(BenchCodernityDB, self).__init__(*args, **kwargs)
def create_database(self):
self.db = Database(self.db_name)
self.db.create()
self.db.add_index(WithSmallNumberIndex(self.db.path, "small_number"))
def delete_database(self):
self.db.close()
shutil.rmtree(self.db_name)
def create(self, record):
self.db.insert(record)
def get(self, key):
return self.db.get("id", key, with_doc=True)
def query(self, **kwargs):
key, val = kwargs.items()[0]
return list(self.db.get_many(key, val, limit=-1, with_doc=True))
示例2: init_db
def init_db():
db = Database(OUTPUT_DB)
try:
db.create()
except IndexConflict:
db.open()
return db
示例3: test_compact_shards
def test_compact_shards(self, tmpdir):
db = Database(str(tmpdir) + '/db')
db.create(with_id_index=False)
db.add_index(ShardedUniqueHashIndex5(db.path, 'id'))
for x in xrange(100):
db.insert({'x': x})
db.compact()
assert db.count(db.all, 'id') == 100
示例4: main
def main():
db = Database("/tmp/tut5_2")
db.create()
x_ind = WithXIndex(db.path, "x")
db.add_index(x_ind)
for x in xrange(100):
db.insert(dict(x=x, t=random.random()))
print db.run("x", "avg", start=10, end=30)
示例5: __init__
def __init__(self):
db = Database('db')
if db.exists():
db.open()
else:
db.create()
index = UrlIndex(db.path, 'urlidx')
db.add_index(index)
self._db = db
示例6: init_store_db
def init_store_db(self):
self.db = Database(os.path.join(self.store_path, "store.db"))
if not self.db.exists():
self.db.create()
self.db.add_index(WithHashIndex(self.db.path, "hash"))
self.db.add_index(WithPointerIndex(self.db.path, "pointer"))
else:
self.db.open()
示例7: CDBBase
class CDBBase(object):
def __init__(self, path, logger = None ):
self.logger = logger or logging.getLogger( __name__ )
self._db = Database(path)
if self._db.exists():
self._db.open()
self.logger.debug( "Abierta con exito la BD '%s'", path )
else:
self.logger.debug( "Creando la BD '%s'", path )
self._db.create()
self._initialitate( self._db )
def _initialitate(self, db):
pass
def get_db(self):
return self._db
示例8: BaseTest
class BaseTest(object):
def setup(self):
self.db = Database(tempfile.mkdtemp())
self.db.create()
add_index(self.db)
self.task_flow_engine = TaskFlowEngine(self.db)
def teardown(self):
shutil.rmtree(self.db.path)
def run_plainly(self, tests=None):
self.setup()
for k, v in self.__class__.__dict__.items():
if k.startswith("test") and isinstance(v, types.FunctionType):
if not tests or (k in tests):
v(self)
self.teardown()
示例9: test_to_many_shards
def test_to_many_shards(self, tmpdir):
db = Database(str(tmpdir) + '/db')
db.create(with_id_index=False)
# it's ok to use sharded directly there
with pytest.raises(IndexPreconditionsException):
db.add_index(ShardedUniqueHashIndex(db.path, 'id', sh_nums=300))
with pytest.raises(IndexPreconditionsException):
db.add_index(ShardedUniqueHashIndex(db.path, 'id', sh_nums=256))
示例10: __init__
def __init__(self, db_path):
self.db = Database(db_path)
if self.db.exists():
self.db.open()
else:
self.db.create()
path_index = PathIndex(self.db.path, 'path')
self.db.add_index(path_index)
path_added_index = PathAddedIndex(self.db.path, 'path_added')
self.db.add_index(path_added_index)
示例11: __init__
class DBImport:
'''
import scan: scans existing self.db and rebuilds config file
create self.db: creates self.db file, master index, question index and table index
'''
def __init__(self,passkey,xtraDB):
self.key = passkey
self.dbName = xtraDB
self.db=Database(self.dbName)
self.importScan()
def __del__(self):
if (self.db.opened):
self.db.close()
# ADD REBUILD OPTION
def importScan(self):
#read from config, as a check
self.db=Database(self.dbName)
if(self.db.exists()):
self.db.open()
self.db.id_ind.enc_key = self.key
for curr in self.db.all('id'): #since first passkey in self.db should be only one there, function only perfomed once
if curr['t'] == 'master':
masterKey=''.join(curr['_id'])
self.DBConfig = AppConfig()
self.DBConfig.putmap('databaseinfo','indexkey',masterKey)#masterkey=value
self.DBConfig.putmap('databaseinfo','databasename',self.dbName)
break
#add else statement for errors if couldnt be written for found
self.db.close()
return True
示例12: __init__
def __init__(self, path, logger = None ):
self.logger = logger or logging.getLogger( __name__ )
self._db = Database(path)
if self._db.exists():
self._db.open()
self.logger.debug( "Abierta con exito la BD '%s'", path )
else:
self.logger.debug( "Creando la BD '%s'", path )
self._db.create()
self._initialitate( self._db )
示例13: main
def main():
db = Database('/tmp/tut5_1')
db.create()
x_ind = WithXIndex(db.path, 'x')
db.add_index(x_ind)
for x in xrange(100):
db.insert(dict(x=x, t=random.random()))
l = []
for curr in db.get_many('x', start=10, end=30, limit=-1, with_doc=True):
l.append(curr['doc']['t'])
print sum(l) / len(l)
示例14: test_insert_get
def test_insert_get(self, tmpdir, sh_nums):
db = Database(str(tmpdir) + '/db')
db.create(with_id_index=False)
n = globals()['ShardedUniqueHashIndex%d' % sh_nums]
db.add_index(n(db.path, 'id'))
l = []
for x in xrange(10000):
l.append(db.insert(dict(x=x))['_id'])
for curr in l:
assert db.get('id', curr)['_id'] == curr
示例15: __init__
def __init__(self,passkey):
self.key = passkey
self.initQuestions = SecuQ(self.key)
self.DBConfig = AppConfig()
self.dbName = self.DBConfig.mapget('databaseinfo')['databasename']
self.db = Database(self.dbName)
initDay = DayEntry(self.key) # checks day hash or creates a new one
self.dayKey = initDay.dayKey