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


Posted in Python onOctober 23, 2014

看看这个logo,有些像python的小蛇吧 。这次介绍的数据库codernityDB是纯python开发的。

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

先前用了下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 相关文章推荐
Python入门篇之数字
Oct 20 Python
举例区分Python中的浅复制与深复制
Jul 02 Python
Django返回json数据用法示例
Sep 18 Python
Python爬取附近餐馆信息代码示例
Dec 09 Python
运用TensorFlow进行简单实现线性回归、梯度下降示例
Mar 05 Python
python 删除指定时间间隔之前的文件实例
Apr 24 Python
python2 与 pyhton3的输入语句写法小结
Sep 10 Python
使用python list 查找所有匹配元素的位置实例
Jun 11 Python
解决pycharm remote deployment 配置的问题
Jun 27 Python
Python Web版语音合成实例详解
Jul 16 Python
Tensorflow 卷积的梯度反向传播过程
Feb 10 Python
Django框架中模型的用法
Jun 10 Python
Python中使用scapy模拟数据包实现arp攻击、dns放大攻击例子
Oct 23 #Python
使用Python开发windows GUI程序入门实例
Oct 23 #Python
手动实现把python项目发布为exe可执行程序过程分享
Oct 23 #Python
python文件操作整理汇总
Oct 21 #Python
Python中input和raw_input的一点区别
Oct 21 #Python
Python中if __name__ == "__main__"详细解释
Oct 21 #Python
Python创建文件和追加文件内容实例
Oct 21 #Python
You might like
VFP与其他应用程序的集成
2006/10/09 PHP
php Imagick获取图片RGB颜色值
2014/07/28 PHP
PHP翻页跳转功能实现方法
2020/11/30 PHP
a标签的css样式四个状态
2021/03/09 HTML / CSS
jquery 结合C#后台的数组对文章的关键字自动添加链接的代码
2011/07/15 Javascript
JS实现侧悬浮浮动实例代码
2013/11/29 Javascript
js 动态加载事件的几种方法总结
2013/12/25 Javascript
基于canvas实现的钟摆效果完整实例
2016/01/26 Javascript
深入理解JS实现快速排序和去重
2016/10/17 Javascript
使用Node.js给图片加水印的方法
2016/11/15 Javascript
微信小程序 textarea 详解及简单使用方法
2016/12/05 Javascript
Vue项目中如何引入icon图标
2018/03/28 Javascript
vue实现点击展开点击收起效果
2018/04/27 Javascript
React性能优化系列之减少props改变的实现方法
2019/01/17 Javascript
node实现mock-plugin中间件的方法
2019/12/25 Javascript
Vue自动构建发布脚本的方法示例
2020/07/24 Javascript
JS实现京东商品分类侧边栏
2020/12/11 Javascript
[08:40]Navi Vs Newbee
2018/06/07 DOTA
Python中random模块用法实例分析
2015/05/19 Python
深入理解Django-Signals信号量
2019/02/19 Python
Python Django 前后端分离 API的方法
2019/08/28 Python
python生成器推导式用法简单示例
2019/10/08 Python
详解python路径拼接os.path.join()函数的用法
2019/10/09 Python
Python qrcode 生成一个二维码的实例详解
2020/02/12 Python
Html5剪切板功能的实现代码
2018/06/29 HTML / CSS
如何查看浏览器对html5的支持情况
2020/12/15 HTML / CSS
Java中有几种方法可以实现一个线程?用什么关键字修饰同步方法?stop()和suspend()方法为何不推荐使用?
2015/08/04 面试题
生产部管理制度
2014/01/31 职场文书
护士岗位职责
2014/02/16 职场文书
质量保证书范本
2014/04/29 职场文书
企业安全生产标语
2014/06/06 职场文书
初中学校对照检查材料
2014/08/19 职场文书
与美同行演讲稿
2014/09/13 职场文书
党员专题组织生活会发言材料
2014/10/17 职场文书
餐饮店长岗位职责
2015/04/14 职场文书
当你焦虑迷茫时,请读读这6句话
2019/07/24 职场文书