Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- NEW GMAIL ROW
- DROP FUNCTION if exists fs_es_gmail_insert() cascade;
- DROP TRIGGER if exists fs_es_gmail_insert_trigger ON gmail;
- CREATE OR REPLACE FUNCTION fs_es_gmail_insert()
- RETURNS TRIGGER as E'#!/bin/bash
- _arr=\'[["orig_msg","all_mail_uid","g_msg_id","msg_id","last_updated","uid"],[\'
- for arg do
- if [ -z "$arg" ]; then
- _arr="$_arr\\\"$arg\\\","
- elif [ ${arg::1} = "{" ]; then
- _arr="$_arr$arg,"
- else
- _arr="$_arr\\\"$arg\\\","
- fi
- _uid="$arg"
- done
- _arr=${_arr::-1}"]]"
- _json=$(printf \'%s\n\' "$_arr" | jq -Mc \'transpose | map({ key: .[0], value: .[1] }) | from_entries\')
- echo "GET /json?gmail=$_json&uid=$_uid" | socat - tcp:0.0.0.0:12501,reuseaddr,nonblock
- ' LANGUAGE plsh;
- CREATE TRIGGER fs_es_gmail_insert_trigger
- BEFORE INSERT ON gmail
- FOR EACH ROW
- EXECUTE PROCEDURE fs_es_gmail_insert();
- -- NEW FILE_IDX ROW
- DROP FUNCTION if exists fs_es_file_idx_insert() cascade;
- DROP TRIGGER if exists fs_es_file_idx_insert_trigger ON file_idx;
- CREATE OR REPLACE FUNCTION fs_es_file_idx_insert()
- RETURNS TRIGGER as E'#!/bin/bash
- _keys=(src_db src_uid _key _filetype _info _run_ocr _metadata last_updated uid _content)
- key_arr=""
- val_arr=""
- pt=0
- for arg do
- k=${_keys[$pt]}
- if [ -n "$arg" ]; then
- key_arr="$key_arr"\'"\'"$k"\'",\'
- if [ k = "uid" ]; then _uid="$arg"; fi
- if [ ${arg::1} = "{" ]; then
- val_arr="$val_arr$arg,"
- else
- val_arr="$val_arr\\\"$arg\\\","
- fi
- fi
- let pt=pt+1
- done
- key_arr=${key_arr::-1}
- val_arr=${val_arr::-1}
- _arr="[[$key_arr],[$val_arr]]"
- echo $_arr > /tmp/tmp
- _json=$(printf \'%s\n\' "$_arr" | jq \'transpose | map({ key: .[0], value: .[1] }) | from_entries\')
- echo "GET /json?file_idx=$_json&uid=$_uid" | socat - tcp:0.0.0.0:12501,reuseaddr,nonblock
- ' LANGUAGE plsh;
- CREATE TRIGGER fs_es_file_idx_insert_trigger
- BEFORE INSERT or UPDATE ON file_idx
- FOR EACH ROW
- EXECUTE PROCEDURE fs_es_file_idx_insert();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement