BedquiltDB 是一款开源的PostgreSQL扩展,专门用于支持jsonb数据类型的存储,并且提供相应的开放API。BedquiltDB 旨在为开发人员提供一种功能强大的工具,在项目的早期阶段,用于处理松散结构化的数据。
优点:
简单开放的API
支持所有编程语言
支持所有SQL语句,包括约束
容易从”loose schema” 模式切换到 “well defined schema”而不需要改变数据库平台。
示例代码:
Python
import pybedquilt bq = pybedquilt.BedquiltClient(dbname='bedquilt_test') projects = bq['projects'] projects.add_constraints({ 'description': {'$required': 1, '$notnull': 1, '$type': 'string'}, 'tags': {'$required': 1, '$type': 'array'} }) projects.insert({ '_id': "BedquiltDB", 'description': "A ghastly hack.", 'quality': "pre-alpha", 'tags': ["json", "postgres", "api"] }) early_projects = projects.find( {'quality': 'pre-alpha'}) api_projects = projects.find( {'tags': ['api']}) cool_project = projects.find_one_by_id('BedquiltDB')
Node.js
var BedquiltClient = require('bedquilt').BedquiltClient; BedquiltClient.connect('localhost', function(err, client) { var tools = client.collection('tools'); tools.find({type: 'blunt'}, function(err, results) { console.log(results); }); });
SQL
select bq_insert( 'orders', '{"_id": "2001515", "customerId": "117176", "items": ["orange_coat", "socks", "plastic_teeth"]}' ); select bq_find( 'orders', '{"customerId": "220011", "items": ["socks"]}' ); select bq_remove_one( 'orders', '{"_id": "4401515"}' );