zombodb 低级api 操作
zombodb 低级api 允许直接从zombodb 索引中进行insert、delete 文档,同时保留了mvcc 的特性,但是数据没有存储在
pg 中,但是也带来数据上的风险,我们需要注意进行es 数据的备份
api 说明
FUNCTION zdb.llapi_direct_insert(index_name regclass, data json) RETURNS void
FUNCTION zdb.llapi_direct_delete(index_name regclass, _id text) RETURNS void
参考例子
这是一个审计日志的功能,数据直接到es 中,而不用存储在pg 中
- 表创建
CREATE TABLE audit (
id serial8 NOT NULL PRIMARY KEY,
action_type char(2),
username varchar(64),
when_happened timestamp DEFAULT now(),
description text
);
- 索引创建
CREATE INDEX idxaudit
ON audit
USING zombodb ((audit.*))
WITH (llapi=true,url='http://elasticsearch:9200/');
- 创建rule
进行数据操作的处理规则定义
CREATE RULE audit_rule
AS ON INSERT TO audit
DO INSTEAD (
SELECT zdb.llapi_direct_insert('idxaudit', to_json(NEW))
);
- 数据添加操作
INSERT INTO audit (action_type, username, description)
VALUES ('aa', 'someuser', 'this is the first audit entry');
INSERT INTO audit (action_type, username, description)
VALUES ('qr', 'otheruser', 'this is the second audit entry');
INSERT INTO audit (action_type, username, description)
VALUES ('zy', 'anotheruser', 'this is the third audit entry');
- 数据查询
select * from audit;
数据为空,说明数据没有存储在pg 中
es 信息查看,从es 中可以看出数据都存储在es 中

- 使用zombodb api 查询数据
聚合查询
SELECT zdb.count('idxaudit', dsl.match_all()); count ;
-[ RECORD 1 ]
count | 3
记录查询
SELECT _id,
(source->>'id')::bigint AS id,
source->>'username' AS username,
source->>'action_type' AS action_type,
(source->>'when_happened')::timestamp AS timestamp,
source->>'description' AS description
FROM zdb.top_hits_with_id('idxaudit', ARRAY['*'], dsl.match_all(), 100);
[ RECORD 1 ]-------------------------------
_id | B8DQ22kBYb7kkl7X_khC
id | 2
username | otheruser
action_type | qr
timestamp | 2019-04-02 02:11:40.731217
description | this is the second audit entry
-[ RECORD 2 ]-------------------------------
_id | BsDQ22kBYb7kkl7X_khC
id | 1
username | someuser
action_type | aa
timestamp | 2019-04-02 02:11:40.731217
description | this is the first audit entry
-[ RECORD 3 ]-------------------------------
_id | CMDQ22kBYb7kkl7X_khC
id | 3
username | anotheruser
action_type | zy
timestamp | 2019-04-02 02:11:40.731217
description | this is the third audit entry
说明
zombodb 提供的低级api 还是很有意义的,用来作为一个日志审计功能,同时较少了pg 数据的存储
参考资料
https://github.com/zombodb/zombodb/blob/master/LLAPI.md
zombodb 低级api 操作的更多相关文章
- Kafka技术内幕 读书笔记之(三) 生产者——消费者:高级API和低级API——基础知识
1. 使用消费组实现消息队列的两种模式 分布式的消息系统Kafka支持多个生产者和多个消费者,生产者可以将消息发布到集群中不同节点的不同分区上:消费者也可以消费集群中多个节点的多个分区上的消息 . 写 ...
- 转 用C API 操作MySQL数据库
用C API 操作MySQL数据库 参考MYSQL的帮助文档整理 这里归纳了C API可使用的函数,并在下一节详细介绍了它们.请参见25.2.3节,“C API函数描述”. 函数 描述 mysql_a ...
- hive-通过Java API操作
通过Java API操作hive,算是测试hive第三种对外接口 测试hive 服务启动 package org.admln.hive; import java.sql.SQLException; i ...
- Hadoop学习记录(3)|HDFS API 操作|RPC调用
HDFS的API操作 URL方式访问 package hdfs; import java.io.IOException; import java.io.InputStream; import java ...
- HBase 6、用Phoenix Java api操作HBase
开发环境准备:eclipse3.5.jdk1.7.window8.hadoop2.2.0.hbase0.98.0.2.phoenix4.3.0 1.从集群拷贝以下文件:core-site.xml.hb ...
- hadoop2-HBase的Java API操作
Hbase提供了丰富的Java API,以及线程池操作,下面我用线程池来展示一下使用Java API操作Hbase. 项目结构如下: 我使用的Hbase的版本是 hbase-0.98.9-hadoop ...
- 使用Java API操作HDFS文件系统
使用Junit封装HFDS import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.*; import org ...
- HBase API操作
|的ascII最大ctrl+shift+t查找类 ctrl+p显示提示 HBase API操作 依赖的jar包 <dependencies> <dependency> < ...
- MSComm控件与Win32 API操作串口有何区别?
MSComm控件与Win32 API操作串口有何区别? [问题点数:50分,结帖人shell_shell] 收藏帖子 回复 我是一个小兵,在战场上拼命! 结帖率 83.33% 我以前用MSCo ...
随机推荐
- git pull代码冲突。怪异问题,了解一下
当远程仓库代码与本地代码产生冲突,无法 pull,且决定放弃本地代码的时候. 或者, 碰见我这种不知道什么问题的情况, pull 成功了,但是远程仓库代码和本地代码竟然也不一样. 天呐,网管常规操作, ...
- 7.4 GRASP原则四:控制器 Controller
4.GRASP原则四:控制器 Controller What first object beyond the UI layer receives and co-ordinates (control ...
- 活动代码页437--修改windows的系统编码
1.首先查看系统编码 win+R打开运行,输入cmd回车,打开命令提示符窗口,输入chcp回车,会查询当前系统的活动代码页,它指明了当前系统使用的编码: 或者,打开cmd后,点击cmd窗口左上角图标, ...
- Win10安装CAD2006
以管理员身份运行 提示如下问题: 查看该隐藏文件如下: 开始以为是未安装MSI Runtime 3.0和.NET Framework Runtime 1.1的原因,下载并安装后还是提示如上问题. 仔细 ...
- Win10系列:C#应用控件进阶1
线形 线形没有内部空间,若要呈现一条直线,需要用Line对象的Stroke和StrokeThickness 属性分别为其轮廓的颜色及轮廓的粗细赋值,若不设置这两个属性,线形将不会呈现.绘制一条线形图形 ...
- SpringMVC 搭建遇到的坑
1. Caused by: org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 60; cvc-complex-type.2.4.c ...
- python项目运行环境安装小结
安装最新即可,实际的版本号可能不一样 安装过程较复杂,建议用一台单独的vm安装,能做成docker image最好 基础软件 nginx-1.10.0: sudo apt-get install ng ...
- [Leetcode 78]求子集 Subset
[题目] Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The ...
- Zabbix4.0报警配置-企业微信报警
一:前期准备 1.1:企业号注册 https://qy.weixin.qq.com/ 微信调用接口说明 http://qydev.weixin.qq.com/wiki/index.php?title ...
- 操作系统の实验四 windows中线程的创建和同步控制
摘要: 1.创建信号量 HANDLE CreateSemaphore( LPSECURITY_ATTIBUTES lpSemaphoreAttributes, LONG lInitialCount; ...