纯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中的多进程与多线程的使用
Apr 07 Python
Swift中的协议(protocol)学习教程
Jul 08 Python
深入解析Python的Tornado框架中内置的模板引擎
Jul 11 Python
Python字典操作详细介绍及字典内建方法分享
Jan 04 Python
python使用生成器实现可迭代对象
Mar 20 Python
详解python编译器和解释器的区别
Jun 24 Python
Python箱型图绘制与特征值获取过程解析
Oct 22 Python
解决pyecharts运行后产生的html文件用浏览器打开空白
Mar 11 Python
Python函数默认参数常见问题及解决方案
Mar 26 Python
在python中利用pycharm自定义代码块教程(三步搞定)
Apr 15 Python
Spark处理数据排序问题如何避免OOM
May 21 Python
python套接字socket通信
Apr 01 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入门基础之php代码写法
2011/12/30 PHP
解析如何用php screw加密php源代码
2013/06/20 PHP
async和DOM Script文件加载比较
2014/07/20 PHP
php实现用于删除整个目录的递归函数
2015/03/16 PHP
js自带函数备忘 数组
2006/12/29 Javascript
JavaScript 监听textarea中按键事件
2009/10/08 Javascript
js使用函数绑定技术改变事件处理程序的作用域
2011/12/26 Javascript
jQuery聚合函数实例
2015/05/21 Javascript
JavaScript Length 属性的总结
2015/11/02 Javascript
JavaScript使用Range调色及透明度实例
2016/09/25 Javascript
JavaScript获取键盘按键的键码(参照表)
2017/01/10 Javascript
jQuery读取XML文件的方法示例
2017/02/03 Javascript
jq.ajax+php+mysql实现关键字模糊查询(示例讲解)
2018/01/02 Javascript
简述vue中的config配置
2018/01/23 Javascript
微信小程序实现的3d轮播图效果示例【基于swiper组件】
2018/12/11 Javascript
vue中轮训器的使用
2019/01/27 Javascript
[43:32]2014 DOTA2华西杯精英邀请赛 5 25 LGD VS NewBee第一场
2014/05/26 DOTA
Python中Selenium模拟JQuery滑动解锁实例
2017/07/26 Python
Python3.4 tkinter,PIL图片转换
2018/06/21 Python
Python爬虫设置代理IP(图文)
2018/12/23 Python
在Python中关于使用os模块遍历目录的实现方法
2019/01/03 Python
python执行精确的小数计算方法
2019/01/21 Python
python+selenium 点击单选框-radio的实现方法
2019/09/03 Python
台湾饭店和机票预订网站:Expedia台湾
2016/08/05 全球购物
微软美国官方网站:Microsoft美国
2018/05/10 全球购物
广州御银科技股份有限公司试卷(C++)
2016/11/04 面试题
一套.net面试题及答案
2016/11/02 面试题
线程同步的方法
2016/11/23 面试题
医学院四年学习生活的自我评价
2013/11/06 职场文书
索桥的故事教学反思
2014/02/06 职场文书
运动会稿件200字
2014/02/07 职场文书
关于中国梦的演讲稿
2014/04/23 职场文书
文明单位申报材料
2014/12/23 职场文书
2015年清明节扫墓演讲稿
2015/03/18 职场文书
MySQL 全文索引使用指南
2021/05/25 MySQL
python简单验证码识别的实现过程
2021/06/20 Python