国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

純Python開發的nosql數據庫CodernityDB介紹和使用實例

2019-11-25 18:07:45
字體:
來源:轉載
供稿:網友

看看這個logo,有些像python的小蛇吧 。這次介紹的數據庫codernityDB是純python開發的。

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

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

主要特點

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

CodernityDB數據庫操作代碼實例:

復制代碼 代碼如下:

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)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉禾县| 绥滨县| 东平县| 横峰县| 肥东县| 晋中市| 郸城县| 阜阳市| 苗栗县| 顺平县| 额尔古纳市| 济源市| 蒲江县| 乐亭县| 洱源县| 邳州市| 永年县| 晋江市| 博罗县| 阳山县| 女性| 渝北区| 横峰县| 五峰| 荆州市| 昆明市| 凤阳县| 兰溪市| 齐齐哈尔市| 江华| 泰顺县| 亚东县| 乌海市| 邵东县| 平乐县| 易门县| 洞口县| 海口市| 惠东县| 柘城县| 兴仁县|