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 操作的更多相关文章

  1. Kafka技术内幕 读书笔记之(三) 生产者——消费者:高级API和低级API——基础知识

    1. 使用消费组实现消息队列的两种模式 分布式的消息系统Kafka支持多个生产者和多个消费者,生产者可以将消息发布到集群中不同节点的不同分区上:消费者也可以消费集群中多个节点的多个分区上的消息 . 写 ...

  2. 转 用C API 操作MySQL数据库

    用C API 操作MySQL数据库 参考MYSQL的帮助文档整理 这里归纳了C API可使用的函数,并在下一节详细介绍了它们.请参见25.2.3节,“C API函数描述”. 函数 描述 mysql_a ...

  3. hive-通过Java API操作

    通过Java API操作hive,算是测试hive第三种对外接口 测试hive 服务启动 package org.admln.hive; import java.sql.SQLException; i ...

  4. Hadoop学习记录(3)|HDFS API 操作|RPC调用

    HDFS的API操作 URL方式访问 package hdfs; import java.io.IOException; import java.io.InputStream; import java ...

  5. 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 ...

  6. hadoop2-HBase的Java API操作

    Hbase提供了丰富的Java API,以及线程池操作,下面我用线程池来展示一下使用Java API操作Hbase. 项目结构如下: 我使用的Hbase的版本是 hbase-0.98.9-hadoop ...

  7. 使用Java API操作HDFS文件系统

    使用Junit封装HFDS import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.*; import org ...

  8. HBase API操作

    |的ascII最大ctrl+shift+t查找类  ctrl+p显示提示 HBase API操作 依赖的jar包 <dependencies> <dependency> < ...

  9. MSComm控件与Win32 API操作串口有何区别?

    MSComm控件与Win32 API操作串口有何区别? [问题点数:50分,结帖人shell_shell]   收藏帖子 回复 我是一个小兵,在战场上拼命!   结帖率 83.33% 我以前用MSCo ...

随机推荐

  1. Codeforces Round #113 (Div. 2) B. Polygons Andrew求凸包

    B. Polygons time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  2. 线程(四)之Queue

    SynchronousQueue SynchronousQueue是无界的,是一种无缓冲的等待队列,但是由于该Queue本身的特性,在某次添加元素后必须等待其他线程取走后才能继续添加:可以认为Sync ...

  3. idea新建一个spring项目,图解

    废话不说直接按图操作 选择Web模块的Web功能,单击Finish,idea会在spring.io网址上下载功能模板,下载玩成之后就是一个完整的Spring Boot工程 Project locati ...

  4. linux iso 下载地址

    Centos 5.3  下载地址: http://www.karan.org/mock/5.3/CentOS-5.3-i386-bin-1to6.torrent http://www.karan.or ...

  5. Servlet的5种方式实现表单提交

    http://www.cnblogs.com/zhanghaoliang/p/5622900.html

  6. javascript高级程序设计第3版——第一章概括

    最近发现Xmind思维导图是个好东西,刚好开始看书,被用来归纳最好不过了

  7. react 表单获取多个input

    react  表单this.handleChange(key,e){ [key]:e.target.value} submit=()=>{ const {userName,age,status} ...

  8. 在数据库中sql查询很快,但在程序中查询较慢的解决方法

    在写java的时候,有一个方法查询速度比其他方法慢很多,但在数据库查询很快,原来是因为程序中使用参数化查询时参数类型错误的原因 select * from TransactionNo, fmis_Ac ...

  9. 基于FPGA的1553B通信模块的设计(转)

    reference:http://www.21ic.com/app/eda/201808/798483.htm https://www.milstd1553.com/ [导读] 摘 要: 提出一种将F ...

  10. js对json字符串和json对象的转换

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...