先前用了下tinyDB這個(gè)本地?cái)?shù)據(jù)庫(kù),也在一個(gè)api服務(wù)中用了下,一開始覺得速度有些不給力,結(jié)果一看實(shí)現(xiàn)的方式,真是太鳥了,居然就是json的存儲(chǔ),連個(gè)二進(jìn)制壓縮都沒有。 這里介紹的CodernityDB 也是純開發(fā)的一個(gè)小數(shù)據(jù)庫(kù)。
CodernityDB是開源的,純Python語言(沒有第三方依賴),快速,多平臺(tái)的NoSQL型數(shù)據(jù)庫(kù)。它有可選項(xiàng)支持HTTP服務(wù)版本(CodernityDB-HTTP),和Python客戶端庫(kù)(CodernityDB-PyClient),它目標(biāo)是100%兼容嵌入式的版本。
主要特點(diǎn)
1.Pyhon原生支持
2.多個(gè)索引
3.快(每秒可達(dá)50 000次insert操作)
4.內(nèi)嵌模式(默認(rèn))和服務(wù)器模式(CodernityDB-HTTP),加上客戶端庫(kù)(CodernityDB-PyClient),能夠100%兼容
5.輕松完成客戶的存儲(chǔ)
CodernityDB數(shù)據(jù)庫(kù)操作代碼實(shí)例:
代碼如下:
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)
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com