纯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计算最大优先级队列实例
Dec 18 Python
对于Python异常处理慎用“except:pass”建议
Apr 02 Python
一个基于flask的web应用诞生 flask和mysql相连(4)
Apr 11 Python
python实现解数独程序代码
Apr 12 Python
Python+树莓派+YOLO打造一款人工智能照相机
Jan 02 Python
python3.7简单的爬虫实例详解
Jul 08 Python
PyTorch中的padding(边缘填充)操作方式
Jan 03 Python
基于python3生成标签云代码解析
Feb 18 Python
借助Paramiko通过Python实现linux远程登陆及sftp的操作
Mar 16 Python
Python使用Pyqt5实现简易浏览器(最新版本测试过)
Apr 27 Python
python re模块和正则表达式
Mar 24 Python
详解Golang如何实现支持随机删除元素的堆
Sep 23 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
php网上商城购物车设计代码分享
2012/02/15 PHP
深入php函数file_get_contents超时处理的方法详解
2013/06/03 PHP
php常用Output和ptions/Info函数集介绍
2013/06/19 PHP
php中如何判断一个网页请求是ajax请求还是普通请求
2013/08/10 PHP
浅谈Laravel核心解读之Console内核
2018/12/02 PHP
PHP基础之输出缓冲区基本概念、原理分析
2019/06/19 PHP
use jscript Create a SQL Server database
2007/06/16 Javascript
一个基于jquery的图片切换效果
2010/07/06 Javascript
最全正则表达式总结:验证QQ号、手机号、Email、中文、邮编、身份证、IP地址等
2017/08/16 Javascript
浅谈关于.vue文件中style的scoped属性
2017/08/19 Javascript
手写Node静态资源服务器的实现方法
2018/03/20 Javascript
js实现延迟加载的几种方法详解
2019/01/19 Javascript
详解vue项目打包步骤
2019/03/29 Javascript
详解Vue前端生产环境发布配置实战篇
2019/05/07 Javascript
JS前端知识点 运算符优先级,URL编码与解码,String,Math,arguments操作整理总结
2019/06/27 Javascript
[04:41]2014DOTA2国际邀请赛 Liquid顺利突围晋级正赛
2014/07/09 DOTA
python登录豆瓣并发帖的方法
2015/07/08 Python
python实现植物大战僵尸游戏实例代码
2019/06/10 Python
python3读取图片并灰度化图片的四种方法(OpenCV、PIL.Image、TensorFlow方法)总结
2019/07/04 Python
python关闭占用端口方式
2019/12/17 Python
Python爬虫获取页面所有URL链接过程详解
2020/06/04 Python
PyCharm+Miniconda3安装配置教程详解
2021/02/16 Python
基于html和CSS3制作酷炫的导航栏
2015/09/23 HTML / CSS
HTML5 WebGL 实现民航客机飞行监控系统
2019/07/25 HTML / CSS
基于HTML5 Canvas的3D动态Chart图表的示例
2017/11/02 HTML / CSS
Corelle官方网站:购买康宁餐具
2016/11/02 全球购物
The North Face北面荷兰官网:美国著名户外品牌
2019/10/16 全球购物
大学四年职业生涯规划书范文
2014/01/02 职场文书
纪检监察建议书
2014/05/19 职场文书
世博会口号
2014/06/20 职场文书
刑事代理授权委托书
2014/09/17 职场文书
个人借款协议书范本
2014/11/17 职场文书
2015欢度元旦标语口号
2014/12/09 职场文书
小学班主任事迹材料
2014/12/17 职场文书
看雷锋电影观后感
2015/06/10 职场文书
行政处罚告知书
2015/07/01 职场文书