纯Python开发的nosql数据库CodernityDB介绍和使用实例

yipeiwu_com5年前Python基础

看看这个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)

相关文章

关于python写入文件自动换行的问题

现在需要一个写文件方法,将selenium的脚本运行结果写入test_result.log文件中 首先创建写入方法 def write_result(str): writeres...

Python浮点数四舍五入问题的分析与解决方法

Python浮点数四舍五入问题的分析与解决方法

问题 昨天遇到一个问题,在 6.6045 保留三位小数时,使用 round() 函数进行计算,我们希望得到 6.605,然而: >>> round(6.6045,...

python将视频转换为全字符视频

python将视频转换为全字符视频

简介 如何简单的使用python来实现将一部视频转换为字符画视频的效果。 其实,大家都知道视频就是一帧一帧的图片构成的。   那么如今我们想要实现,将视频转换为...

Python编程实现正则删除命令功能

本文实例讲述了Python编程实现正则删除命令功能。分享给大家供大家参考,具体如下: 脚本用途: 在DOS下使用del功能箭头,不支持正则表达式的功能。 脚本实现: import s...

pytorch 自定义卷积核进行卷积操作方式

pytorch 自定义卷积核进行卷积操作方式

一 卷积操作:在pytorch搭建起网络时,大家通常都使用已有的框架进行训练,在网络中使用最多就是卷积操作,最熟悉不过的就是 torch.nn.Conv2d(in_channels,...