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


Python Database.insert方法代码示例

本文整理汇总了Python中CodernityDB.database.Database.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Database.insert方法的具体用法?Python Database.insert怎么用?Python Database.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CodernityDB.database.Database的用法示例。


在下文中一共展示了Database.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
def main():
    db = Database('/tmp/tut_update')
    db.create()
    x_ind = WithXIndex(db.path, 'x')
    db.add_index(x_ind)

    # full examples so we had to add first the data
    # the same code as in previous step

    for x in xrange(100):
        db.insert(dict(x=x))

    for y in xrange(100):
        db.insert(dict(y=y))

    # end of insert part

    print db.count(db.all, 'x')

    for curr in db.all('x', with_doc=True):
        doc = curr['doc']
        if curr['key'] % 7 == 0:
            db.delete(doc)
        elif curr['key'] % 5 == 0:
            doc['updated'] = True
            db.update(doc)

    print db.count(db.all, 'x')

    for curr in db.all('x', with_doc=True):
        print curr
开发者ID:abhishekgahlot,项目名称:codernitydb,代码行数:33,代码来源:quick_update.py

示例2: BenchCodernityDB

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
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,代码行数:27,代码来源:bench_codernity.py

示例3: main

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
def main():
    db = Database('/tmp/tut1')
    db.create()

    for x in xrange(100):
        print db.insert(dict(x=x))

    for curr in db.all('id'):
        print curr
开发者ID:abhishekgahlot,项目名称:codernitydb,代码行数:11,代码来源:quick_key_value.py

示例4: test_compact_shards

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
    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,代码行数:12,代码来源:shard_tests.py

示例5: main

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
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,代码行数:12,代码来源:quick_key_value5_2.py

示例6: __init__

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
class cache :
	"""
		cache for word morphological analysis
	"""
	def __init__(self,):
		"""
		Create Analex Cache
		"""
		self.cache={'checkedWords':{},
			    'FreqWords':{'noun':{}, 'verb':{},'stopword':{}},
			};
		self.db = Database('/tmp/qalsadiCache')
		if not self.db.exists():
			self.db.create();
			x_ind = WithAIndex(self.db.path, 'a')
			self.db.add_index(x_ind)        
		else:
			self.db.open();

	def __del__(self):
		"""
		Delete instance and clear cache
		
		"""
		self.cache=None;
		self.db.close();

	def isAlreadyChecked(self, word):
		try:
			return bool(self.db.get('a', word))
		except: return False
		#~ except: return False;

	def getChecked(self, word):
		x = self.db.get('a', word, with_doc=True)
		y= x.get('doc',False);
		if y: return y.get('d',[])
		else: return []
	
	def addChecked(self, word, data):
		idata = {"a":word,'d':data}
		self.db.insert(idata)

	
	def existsCacheFreq(self, word, wordtype):
		return word in self.cache['FreqWords'];
	
	def getFreq(self, originalword, wordtype):
		return self.cache['FreqWords'][wordtype].get(originalword,0);
	
	def addFreq(self, original, wordtype, freq):
		self.cache['FreqWords'][wordtype][original]=freq;
开发者ID:ATouhou,项目名称:mishkal,代码行数:54,代码来源:cache.py

示例7: main

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
def main():
    db = Database('/tmp/tut2')
    db.create()
    x_ind = WithXIndex(db.path, 'x')
    db.add_index(x_ind)

    for x in xrange(100):
        db.insert(dict(x=x))

    for y in xrange(100):
        db.insert(dict(y=y))

    print db.get('x', 10, with_doc=True)
开发者ID:abhishekgahlot,项目名称:codernitydb,代码行数:15,代码来源:quick_key_value2.py

示例8: main

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
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,代码行数:15,代码来源:quick_key_value5_1.py

示例9: main

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
def main():
    db = Database('db/tut2')
    if db.exists():
    	db.open()
    else:
    	db.create()
    x_ind = WithXIndex(db.path, 'y')
    db.add_index(x_ind)

    for x in xrange(100):
        db.insert(dict(x=x))

    for y in xrange(100):
        db.insert(dict(y=y))

    print db.get('x', 10, with_doc=True)
开发者ID:t1g0r,项目名称:ramey,代码行数:18,代码来源:codernity_test.py

示例10: main

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
def main():
    db = Database('/tmp/tut4')
    db.create()
    x_ind = WithXIndex(db.path, 'x')
    db.add_index(x_ind)

    for x in xrange(100):
        db.insert(dict(x=x))

    for y in xrange(100):
        db.insert(dict(y=y))

    print db.get('x', 10, with_doc=True)

    for curr in db.get_many('x', start=15, end=25, limit=-1, with_doc=True):
        print curr
开发者ID:abhishekgahlot,项目名称:codernitydb,代码行数:18,代码来源:quick_key_value4.py

示例11: migrate

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
def migrate(source, destination):
    """
    Very basic for now
    """
    dbs = Database(source)
    dbt = Database(destination)
    dbs.open()
    dbt.create()
    dbt.close()
    for curr in os.listdir(os.path.join(dbs.path, "_indexes")):
        if curr != "00id.py":
            shutil.copyfile(os.path.join(dbs.path, "_indexes", curr), os.path.join(dbt.path, "_indexes", curr))
    dbt.open()
    for c in dbs.all("id"):
        del c["_rev"]
        dbt.insert(c)
    return True
开发者ID:Adelscott,项目名称:persomov,代码行数:19,代码来源:migrate.py

示例12: main

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
def main():
    db = Database('/tmp/demo_secure')
    key = 'abcdefgh'
    id_ind = EncUniqueHashIndex(db.path, 'id', storage_class='Salsa20Storage')
    db.set_indexes([id_ind])
    db.create()
    db.id_ind.enc_key = key

    for x in xrange(100):
        db.insert(dict(x=x, data='testing'))

    db.close()
    dbr = Database('/tmp/demo_secure')
    dbr.open()
    dbr.id_ind.enc_key = key

    for curr in dbr.all('id', limit=5):
        print curr
开发者ID:abhishekgahlot,项目名称:codernitydb,代码行数:20,代码来源:demo_secure_storage.py

示例13: main

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
def main():
    db = Database("/tmp/demo_secure")
    key = "abcdefgh"
    id_ind = EncUniqueHashIndex(db.path, "id")
    db.set_indexes([id_ind])
    db.create()
    db.id_ind.enc_key = key
    print db.id_ind.storage

    for x in xrange(100):
        db.insert(dict(x=x, data="testing"))

    db.close()
    dbr = Database("/tmp/demo_secure")
    dbr.open()
    dbr.id_ind.enc_key = key

    for curr in dbr.all("id", limit=5):
        print curr
开发者ID:perchouli,项目名称:codernitydb,代码行数:21,代码来源:demo_secure_storage.py

示例14: test_insert_get

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
    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,代码行数:13,代码来源:shard_tests.py

示例15: CodernityDataStore

# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import insert [as 别名]
class CodernityDataStore(object):
    PATH_TYPE = 'path'

    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)

    @classmethod
    def dt_str(cls, datetime):
        return datetime.isoformat()[0:19]

    def add_video(self, path, video, added=None):
        logger.debug("add_video(%s, %s, %s)", path, video, added)
        added = added or datetime.utcnow()

        existing = list(self.db.get_many('path', path, with_doc=True))

        video_data, video_type = Serializer.serialize_video(video)
        data = dict(_t=self.PATH_TYPE, path=path, video_data=video_data, video_type=video_type,
                    downloads=dict(), added=self.dt_str(added))
        self.db.insert(data)

        for existing_path in existing:
            self.db.delete(existing_path['doc'])

    def add_download(self, path, provider, sub_id, language, score):
        logger.debug("add_download(%s, %s, %s, %s, %d)", path, provider, sub_id, language, score)
        data = self.db.get('path', path, with_doc=True)
        path = data['doc']
        download = dict(provider=provider, sub_id=sub_id, lang=str(language), score=score)
        if str(language) in path['downloads']:
            path['downloads'][str(language)].append(download)
        else:
            path['downloads'][str(language)] = [download]
        self.db.update(path)

    def get_downloads_for_video(self, path):
        logger.debug("get_downloads_for_video(%s)", path)
        data = self.db.get('path', path, with_doc=True)
        return data['doc']['downloads']

    @staticmethod
    def exceeds_desired_score(video, score, desired_movie_score, desired_episode_score):
        if isinstance(video, Episode):
            return score >= desired_episode_score
        elif isinstance(video, Movie):
            return score >= desired_movie_score

    def get_incomplete_videos(self, languages, desired_movie_score, desired_episode_score, ignore_older_than):
        logger.debug("get_incomplete_videos(%s, %d, %d, %s)", languages, desired_movie_score, desired_episode_score, ignore_older_than)
        within_date = self.db.get_many('path_added', start=self.dt_str(ignore_older_than), with_doc=True)
        results = []
        for path in (data['doc'] for data in within_date):
            video = Serializer.deserialize_video(path['video_type'], path['video_data'])
            needs = []
            for lang in languages:
                if str(lang) in path['downloads']:
                    current_score = max(download['score'] for download in path['downloads'][str(lang)])
                    if not self.exceeds_desired_score(video, current_score, desired_movie_score, desired_episode_score):
                        needs.append(dict(lang=lang, current_score=current_score))
                else:
                    needs.append(dict(lang=lang, current_score=0))
            if needs:
                results.append(dict(path=path['path'], video=video, needs=needs))

        logger.debug("found %d incomplete videos: %s", len(results), results)
        return results

    def close(self):
        self.db.close()
开发者ID:NigelRook,项目名称:superliminal,代码行数:79,代码来源:datastore.py


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