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

yipeiwu_com5年前Python基础

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

先前用了下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中单下划线_的常见用法总结

这篇文章给大家介绍python中单下划线_,具体内容如下所示: 前言 我们在阅读源码的时候经常会看到各种单下划线_的使用,所以今天特地做一个总结,而且其实很多(不是所有)关于下划线的使用...

linux中如何使用python3获取ip地址

前言 这篇文章主要介绍了linux中如何使用python3获取ip地址,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下。 一、不带参数...

Python3基于sax解析xml操作示例

Python3基于sax解析xml操作示例

本文实例讲述了Python3基于sax解析xml操作。分享给大家供大家参考,具体如下: python使用SAX解析xml SAX是一种基于事件驱动的API。 利用SAX解析XML文档牵涉...

python多线程案例之多任务copy文件完整实例

python多线程案例之多任务copy文件完整实例

本文实例讲述了python多线程案例之多任务copy文件。分享给大家供大家参考,具体如下: import os import multiprocessing def copy_fil...

Python实现给qq邮箱发送邮件的方法

本文实例讲述了Python实现给qq邮箱发送邮件的方法。分享给大家供大家参考。具体实现方法如下: #-*-coding:utf-8-*- #===================...