Last active
October 6, 2016 13:14
-
-
Save audreyt/5317943 to your computer and use it in GitHub Desktop.
plv8 SQL for the |> and <| operators (aka LiveScript application): SELECT '{"hello": [1,2,3]}' |> 'this.hello[0]';
SELECT 'this.hello[0]' <| '{"hello": [1,2,3]}';
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION plv8x.json_eval(code text) RETURNS plv8x.json AS $$ | |
| return JSON.stringify( | |
| eval("(function(){return #code})").apply(this) | |
| ); | |
| $$ LANGUAGE plls IMMUTABLE STRICT; | |
| CREATE OR REPLACE FUNCTION plv8x.json_eval(data plv8x.json, code text) RETURNS plv8x.json AS $$ | |
| return JSON.stringify( | |
| eval("(function(){return #code})").apply(JSON.parse(data)) | |
| ); | |
| $$ LANGUAGE plls IMMUTABLE STRICT; | |
| CREATE OR REPLACE FUNCTION plv8x.json_eval(code text, data plv8x.json) RETURNS plv8x.json AS $$ | |
| return JSON.stringify( | |
| eval("(function(){return #code})").apply(JSON.parse(data)) | |
| ); | |
| $$ LANGUAGE plls IMMUTABLE STRICT; | |
| DROP OPERATOR IF EXISTS |> (text); | |
| CREATE OPERATOR |> ( | |
| RIGHTARG = text, | |
| PROCEDURE = plv8x.json_eval | |
| ); | |
| DROP OPERATOR IF EXISTS |> (plv8x.json, text); | |
| CREATE OPERATOR |> ( | |
| LEFTARG = plv8x.json, | |
| RIGHTARG = text, | |
| COMMUTATOR = <|, | |
| PROCEDURE = plv8x.json_eval | |
| ); | |
| DROP OPERATOR IF EXISTS <| (text, plv8x.json); | |
| CREATE OPERATOR <| ( | |
| LEFTARG = text, | |
| RIGHTARG = plv8x.json, | |
| COMMUTATOR = |>, | |
| PROCEDURE = plv8x.json_eval | |
| ); | |
| SELECT '{"hello": [1,2,3]}' |> 'this.hello[0]'; | |
| SELECT 'this.hello[0]' <| '{"hello": [1,2,3]}'; | |
| SELECT |> '1+1'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment