Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%sql postgres@system
- -- GET GMAIL ROW AS JSON
- DROP FUNCTION IF EXISTS es_gmail_row_with_gmail_uid(integer);
- CREATE OR REPLACE FUNCTION es_gmail_row_with_gmail_uid(gmail_uid integer)
- RETURNS text AS $funct$
- from subprocess import Popen as sub_popen
- from subprocess import PIPE as sub_PIPE
- T = {'gmail_uid' : gmail_uid}
- qry = """
- SELECT row_to_json(t) res
- FROM (select *
- from (
- SELECT * FROM gmail
- WHERE uid = %(gmail_uid)s
- ) f
- ) t
- """ % T
- cmd = [ 'echo "GET /json?gmail=%s"' % plpy.execute(qry)[0]["res"],
- ' | socat - unix:/var/sockets/web_socket_relay.sock,nonblock' ]
- #cmd = [ 'echo "GET /json?gmail=%s"' % plpy.execute(qry)[0]["res"],
- # ' > /tmp/tmp' ]
- (_out,_err) = sub_popen(''.join(cmd),stdout=sub_PIPE,shell=True).communicate()
- assert _err is None
- $funct$
- LANGUAGE plpythonu;
- %%sql postgres@system
- -- GET FILE IDX ROW AS JSON
- DROP FUNCTION IF EXISTS es_file_idx_row_with_gmail_uid(integer);
- CREATE OR REPLACE FUNCTION es_file_idx_row_with_gmail_uid(gmail_uid integer)
- RETURNS text AS $funct$
- from subprocess import Popen as sub_popen
- from subprocess import PIPE as sub_PIPE
- T = {'gmail_uid' : gmail_uid}
- qry = """
- SELECT row_to_json(t) res
- FROM (select *
- from (
- SELECT * FROM file_idx
- WHERE src_uid = %(gmail_uid)s
- ) f
- ) t
- """ % T
- cmd = [ 'echo \'GET /json?file_idx=%s\'' % plpy.execute(qry)[0]["res"],
- ' | socat - unix:/var/sockets/web_socket_relay.sock,nonblock' ]
- (_out,_err) = sub_popen(''.join(cmd),stdout=sub_PIPE,shell=True).communicate()
- assert _err is None
- $funct$
- LANGUAGE plpythonu;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement