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 ...
随机推荐
- Mac配置Scala和Spark最详细过程
Mac配置Scala和Spark最详细过程 原文链接: http://www.cnblogs.com/blog5277/p/8567337.html 原文作者: 博客园--曲高终和寡 一,准备工作 1 ...
- MVC强类型视图,详细信息展示【五】
一.在MVC三种讲到两种后端发送数据到前端的方法,今天讲的是第三种,发送过去的方法 [强类型视图]. 1. 强类型视图,就是指在传递的过程中只能传递一种类型的数据到该视图中,就比如默认的传递的数据类型 ...
- echarts4的学习
echarts的学习 1.echarts的全解注释.https://www.2cto.com/kf/201708/665624.html ### 2.从echarts3开始学习echarts源码.ht ...
- fcn+caffe+voc2012实验记录
参考博客: http://blog.csdn.net/haoji007/article/details/77148374 http://blog.csdn.net/jacke121/article/d ...
- Linux出现wrong ELF class: ELFCLASS64
安装软件时出现问题 ×.so.×:wrong ELF class: ELFCLASS64 ,大致的意思是软件是32位的,需要32位的 ×.so.×动态链接库,而系统是64位的所提供的该 动态链接库 ...
- 『TensorFlow』流程控制之tf.identity
一个详细介绍 下面程序要做的是,5次循环,每次循环给x加1,赋值给y,然后打印出来, x = tf.Variable(0.0) #返回一个op,表示给变量x加1的操作 x_plus_1 = tf.as ...
- vue的组件之间传值方法
父组件 <template> <div> 这是父组件 <children v-bind:parentToChild="toChild" v-on:sh ...
- Python requests代理
self.ip=requests.get('http:ip获取') self.ip=(self.ip.text).replace('\r','').replace('\n','') print('IP ...
- Canvas---clearRect()清除圆形区域
function clearArcFun(x,y,r,cxt){ //(x,y)为要清除的圆的圆心,r为半径,cxt为context var stepClear=1;//别忘记这一步 clearArc ...
- hello1
1:选择hello1文件夹并单击“打开项目”.展开“Web页”节点,然后双击该index.xhtml文件以在编辑器中查看它. 该index.xhtml文件是Facelets应用程序的默认登录页面.在典 ...