欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

純Python開發(fā)的nosql數(shù)據(jù)庫CodernityDB介紹和使用實例

 更新時間:2014年10月23日 10:54:02   投稿:junjie  
這篇文章主要介紹了純Python開發(fā)的nosql數(shù)據(jù)庫CodernityDB介紹和使用實例,本文實例包含數(shù)據(jù)插入、數(shù)據(jù)更新、數(shù)據(jù)刪除、數(shù)據(jù)查詢等,需要的朋友可以參考下

看看這個logo,有些像python的小蛇吧 。這次介紹的數(shù)據(jù)庫codernityDB是純python開發(fā)的。

先前用了下tinyDB這個本地數(shù)據(jù)庫,也在一個api服務中用了下,一開始覺得速度有些不給力,結果一看實現(xiàn)的方式,真是太鳥了,居然就是json的存儲,連個二進制壓縮都沒有。  這里介紹的CodernityDB 也是純開發(fā)的一個小數(shù)據(jù)庫。

CodernityDB是開源的,純Python語言(沒有第三方依賴),快速,多平臺的NoSQL型數(shù)據(jù)庫。它有可選項支持HTTP服務版本(CodernityDB-HTTP),和Python客戶端庫(CodernityDB-PyClient),它目標是100%兼容嵌入式的版本。

主要特點

1.Pyhon原生支持
2.多個索引
3.快(每秒可達50 000次insert操作)
4.內嵌模式(默認)和服務器模式(CodernityDB-HTTP),加上客戶端庫(CodernityDB-PyClient),能夠100%兼容
5.輕松完成客戶的存儲

CodernityDB數(shù)據(jù)庫操作代碼實例:

復制代碼 代碼如下:

Insert(simple)
 
from CodernityDB.database import Database
 
db = Database('/tmp/tut1')
db.create()
 
insertDict = {'x': 1}
print db.insert(insertDict)
 
 
 
 
Insert
 
from CodernityDB.database import Database
from CodernityDB.hash_index import HashIndex
 
class WithXIndex(HashIndex):
    def __init__(self, *args, **kwargs):
        kwargs['key_format'] = 'I'
        super(WithXIndex, self).__init__(*args, **kwargs)
 
    def make_key_value(self, data):
        a_val = data.get("x")
        if a_val is not None:
            return a_val, None
        return None
 
    def make_key(self, key):
        return key
 
db = Database('/tmp/tut2')
db.create()
 
x_ind = WithXIndex(db.path, 'x')
db.add_index(x_ind)
 
print db.insert({'x': 1})
 
 
 
Count
 
from CodernityDB.database import Database
 
db = Database('/tmp/tut1')
db.open()
 
print db.count(db.all, 'x')
 
 
Get
 
from CodernityDB.database import Database
 
db = Database('/tmp/tut2')
db.open()
 
print db.get('x', 1, with_doc=True)
 
 
Delete
 
from CodernityDB.database import Database
 
db = Database('/tmp/tut2')
db.open()
 
curr = db.get('x', 1, with_doc=True)
doc  = curr['doc']
 
db.delete(doc)
 
 
 
Update
 
from CodernityDB.database import Database
 
db = Database('/tmp/tut2')
db.create()
 
curr = db.get('x', 1, with_doc=True)
doc  = curr['doc']
 
doc['Updated'] = True
db.update(doc)

相關文章

最新評論