纯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检测是文件还是目录的方法
Jul 03 Python
python机器学习案例教程——K最近邻算法的实现
Dec 28 Python
Python cookbook(数据结构与算法)字典相关计算问题示例
Feb 18 Python
python 获取字符串MD5值方法
May 29 Python
基于python实现名片管理系统
Nov 30 Python
spark dataframe 将一列展开,把该列所有值都变成新列的方法
Jan 29 Python
Python中py文件转换成exe可执行文件的方法
Jun 14 Python
pandas 时间格式转换的实现
Jul 06 Python
python 下 CMake 安装配置 OPENCV 4.1.1的方法
Sep 30 Python
python mysql中in参数化说明
Jun 05 Python
如何基于Django实现上下文章跳转
Sep 16 Python
python 制作网站小说下载器
Feb 20 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
Terran热键控制
2020/03/14 星际争霸
社区(php&&mysql)六
2006/10/09 PHP
一篇不错的PHP基础学习笔记
2007/03/18 PHP
PHP迭代器的内部执行过程详解
2013/11/12 PHP
PHP count()函数讲解
2019/02/03 PHP
javascript while语句和do while语句的区别分析
2007/12/08 Javascript
javascript parseInt 函数分析(转)
2009/03/21 Javascript
select 控制网页内容隐藏于显示的实现代码
2010/05/25 Javascript
JavaScript实现快速排序(自已编写)
2012/12/19 Javascript
js同比例缩放图片的小例子
2013/10/30 Javascript
js showModalDialog弹出窗口实例详解
2014/01/07 Javascript
Jquery图片延迟加载插件jquery.lazyload.js的使用方法
2014/05/21 Javascript
JavaScript利用正则表达式去除日期中的“-”
2014/07/01 Javascript
js使用DOM设置单选按钮、复选框及下拉菜单的方法
2015/01/20 Javascript
jquery任意位置浮动固定层插件用法实例
2015/05/29 Javascript
学习JavaScript正则表达式
2015/11/13 Javascript
jQuery对象的链式操作用法分析
2016/05/10 Javascript
angular2 ng build部署后base文件路径问题详细解答
2017/07/15 Javascript
ES6 Iterator接口和for...of循环用法分析
2019/07/31 Javascript
vue日历/日程提醒/html5本地缓存功能
2019/09/02 Javascript
js实现简单五子棋游戏
2020/05/28 Javascript
以一个投票程序的实例来讲解Python的Django框架使用
2016/02/18 Python
Python注释详解
2016/06/01 Python
python中单例常用的几种实现方法总结
2018/10/13 Python
python判断文件夹内是否存在指定后缀文件的实例
2019/06/10 Python
python的re模块使用方法详解
2019/07/26 Python
html5中使用hotcss.js实现手机端自适配的方法
2020/04/23 HTML / CSS
工作的心得体会
2013/12/31 职场文书
2014年公司迎新年活动方案
2014/02/24 职场文书
公开承诺书格式
2014/05/21 职场文书
纪律教育月活动总结
2014/08/26 职场文书
教师三严三实学习心得体会
2014/10/11 职场文书
2014年个人委托书范本
2014/10/13 职场文书
党员作风建设整改方案
2014/10/27 职场文书
家长会主持词开场白
2015/05/29 职场文书
CSS+HTML 实现顶部导航栏功能
2021/08/30 HTML / CSS