手机
当前位置:查字典教程网 >脚本专栏 >python >纯Python开发的nosql数据库CodernityDB介绍和使用实例
纯Python开发的nosql数据库CodernityDB介绍和使用实例
摘要:看看这个logo,有些像python的小蛇吧。这次介绍的数据库codernityDB是纯python开发的。先前用了下tinyDB这个本地数...

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

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

先前用了下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开发的nosql数据库CodernityDB介绍和使用实例】相关文章:

2款Python内存检测工具介绍和使用方法

python实现的udp协议Server和Client代码实例

python解析html开发库pyquery使用方法

Python基本数据类型详细介绍

在python中的socket模块使用代理实例

python数据结构树和二叉树简介

python快速排序代码实例

python创建和使用字典实例详解

python迭代器的使用方法实例

python的绘图工具matplotlib使用实例

精品推荐
分类导航