纯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 collections模块实例讲解
Apr 07 Python
python实现类似ftp传输文件的网络程序示例
Apr 08 Python
Python线程中对join方法的运用的教程
Apr 09 Python
Python2.7读取PDF文件的方法示例
Jul 13 Python
Python字符串格式化的方法(两种)
Sep 19 Python
Python实现简单的HttpServer服务器示例
Sep 25 Python
利用Python如何生成便签图片详解
Jul 09 Python
浅谈python实现Google翻译PDF,解决换行的问题
Nov 28 Python
Python获取航线信息并且制作成图的讲解
Jan 03 Python
使用pyecharts生成Echarts网页的实例
Aug 12 Python
OpenCV中VideoCapture类的使用详解
Feb 14 Python
Pandas数据类型之category的用法
Jun 28 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递归函数中使用return的注意事项
2014/01/17 PHP
PHP函数http_build_query使用详解
2014/08/20 PHP
php实现上传图片文件代码
2015/07/19 PHP
php版微信js-sdk支付接口类用法示例
2016/10/12 PHP
利用PHP判断是手机移动端还是PC端访问的函数示例
2017/12/14 PHP
阿里对象存储OSS在laravel框架中的使用方法
2019/10/13 PHP
一款JavaScript压缩工具:X2JSCompactor
2007/06/13 Javascript
本地对象Array的原型扩展实现代码
2010/12/04 Javascript
jquery的ajax()函数传值中文乱码解决方法介绍
2012/11/08 Javascript
Javascript 绘制 sin 曲线过程附图
2014/08/21 Javascript
jQuery点击其他地方时菜单消失的实现方法
2016/04/22 Javascript
JS简单实现点击复制链接的方法
2016/08/03 Javascript
Angular 4.x 动态创建表单实例
2017/04/25 Javascript
js使用xml数据载体实现城市省份二级联动效果
2017/11/08 Javascript
echarts鼠标覆盖高亮显示节点及关系名称详解
2018/03/17 Javascript
使用validate.js实现表单数据提交前的验证方法
2018/09/04 Javascript
ant design中upload组件上传大文件,显示进度条进度的实例
2020/10/29 Javascript
[05:42]DOTA2英雄梦之声_第10期_蝙蝠骑士
2014/06/21 DOTA
[43:24]VG vs Serenity 2018国际邀请赛小组赛BO2 第二场 8.17
2018/08/20 DOTA
讲解Python中的标识运算符
2015/05/14 Python
Python下载指定页面上图片的方法
2016/05/12 Python
Python安装Numpy和matplotlib的方法(推荐)
2017/11/02 Python
python实现飞机大战
2018/09/11 Python
Django 创建后台,配置sqlite3教程
2019/11/18 Python
Python 3.8 新功能来一波(大部分人都不知道)
2020/03/11 Python
记录模型训练时loss值的变化情况
2020/06/16 Python
萨克斯第五大道的折扣店:Saks Fifth Avenue OFF 5TH
2016/08/25 全球购物
无畏的旅行:Intrepid Travel
2017/12/20 全球购物
Geekbuying波兰:购买中国电子产品
2019/10/20 全球购物
《胡杨》教学反思
2014/02/16 职场文书
体育教学随笔感言
2014/02/24 职场文书
汽车检测与维修专业求职信
2014/07/04 职场文书
公务员培的训心得体会
2014/09/01 职场文书
地道战观后感300字
2015/06/04 职场文书
企业安全生产规章制度
2015/08/06 职场文书
Python 中面向接口编程
2022/05/20 Python