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 ...
随机推荐
- Pandas 基础(9) - 组合方法 merge
首先, 还是以天气为例, 准备如下数据: df1 = pd.DataFrame({ 'city': ['newyork', 'chicago', 'orlando'], 'temperature': ...
- [IDE - Eclipse] JSP报错:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
是因为Eclipse的Web项目不自动引入相关jar包. Right Click on the Project ❯ Properties ❯ Project Facets. You would be ...
- Node.js简述
Node.js是2009年5月由Ryan Dahl 发布的服务器程序. 它封装了Google V8 JavaScript 引擎, 并将其重建为可在服务器上使用. 它旨在提供一种简单的构建可伸缩网络程序 ...
- Struts2中 Action class not found 问题
刚学Struts2时碰到了以下两个问题,都是没有正确配置struts.xml导致的,自己记录一下: 1.浏览器报404:The origin server did not find a current ...
- python __init__.py 的作用
__init__.py的主要作用是: . Python中package的标识,不能删除 . 定义__all__用来模糊导入 . 编写Python代码(不建议在__init__中写python模块,可以 ...
- 238. Product of Array Except Self除自身以外数组的乘积
网址:https://leetcode.com/problems/product-of-array-except-self/ 参考:https://leetcode.com/problems/prod ...
- System.Web.WebPages.Html.HtmlHelper”不包含XXXX
1.关闭Visual Studio中 2.删除bin和OBJ文件夹 3.重新打开您的解决方案
- Failed to process import candidates for configuration class [com.simple.....]
主要原因: 是因为自己定制的starter在打包时(package)用了spring-boot-maven-plugin,即在你的定制starter工程的pom.xml中有如下配置: <buil ...
- 20175227张雪莹 2018-2019-2 《Java程序设计》第五周学习总结
20175227张雪莹 2018-2019-2 <Java程序设计>第五周学习总结 教材学习内容总结 第六章接口与实现 接口 接口体中所有的常量访问权限一定是public和static(可 ...
- JVM的永久代会发生垃圾回收吗?
垃圾回收不会发生在永久代中.当永久代满或者超过临界值时,就会触发完全垃圾回收(Full GC).如果仔细查看垃圾收集器中的输出信息,就会发现永久代也是被回收的.这就是正确的永久代大小对避免Full G ...