當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。