当前位置: 首页>>代码示例>>Python>>正文


Python database.Database类代码示例

本文整理汇总了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))
开发者ID:jamalex,项目名称:no-sql-bench,代码行数:25,代码来源:bench_codernity.py

示例2: init_db

def init_db():
    db = Database(OUTPUT_DB)

    try:
        db.create()
    except IndexConflict:
        db.open()

    return db
开发者ID:andresriancho,项目名称:pico,代码行数:9,代码来源:timing-collector.py

示例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
开发者ID:amitbmas07,项目名称:codernitydb,代码行数:10,代码来源:shard_tests.py

示例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)
开发者ID:nettedfish,项目名称:codernitydb,代码行数:10,代码来源:quick_key_value5_2.py

示例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
开发者ID:Yustos,项目名称:FeedFilter,代码行数:9,代码来源:cache.py

示例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()
开发者ID:PapajaLM,项目名称:Backuping,代码行数:8,代码来源:store.py

示例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
开发者ID:Gonlo2,项目名称:PyUpManager,代码行数:18,代码来源:CDBBase.py

示例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()
开发者ID:xiechao06,项目名称:lite-task-flow,代码行数:18,代码来源:test.py

示例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))
开发者ID:amitbmas07,项目名称:codernitydb,代码行数:8,代码来源:shard_tests.py

示例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)
开发者ID:NigelRook,项目名称:superliminal,代码行数:10,代码来源:datastore.py

示例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
开发者ID:fflowres,项目名称:Scripts,代码行数:52,代码来源:DBImportClass.py

示例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 )
开发者ID:Gonlo2,项目名称:PyUpManager,代码行数:11,代码来源:CDBBase.py

示例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)
开发者ID:abhishekgahlot,项目名称:codernitydb,代码行数:13,代码来源:quick_key_value5_1.py

示例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
开发者ID:amitbmas07,项目名称:codernitydb,代码行数:11,代码来源:shard_tests.py

示例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
开发者ID:fflowres,项目名称:Scripts,代码行数:14,代码来源:DBInputClass.py


注:本文中的CodernityDB.database.Database类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。