Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into debian
Browse files Browse the repository at this point in the history
  • Loading branch information
ept committed Oct 12, 2011
2 parents 54aa56a + 4f1bed5 commit 564edaf
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 106 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -9,8 +9,8 @@ MODULE_big = plv8
EXTENSION = plv8
DATA = plv8.control plv8--1.0.sql
DATA_built = plv8.sql
REGRESS = init-extension plv8 inline
SHLIB_LINK += -lv8
REGRESS = init-extension plv8 inline json
override SHLIB_LINK += -lv8

CCFLAGS := $(filter-out -Wmissing-prototypes, $(CFLAGS))
CCFLAGS := $(filter-out -Wdeclaration-after-statement, $(CCFLAGS))
Expand Down
37 changes: 37 additions & 0 deletions expected/json.out
@@ -0,0 +1,37 @@
CREATE FUNCTION valid_json(json text) RETURNS boolean
LANGUAGE plv8 IMMUTABLE STRICT
AS $$
try {
JSON.parse(json);
return true;
} catch(e) {
return false;
}
$$;
CREATE DOMAIN json AS text
CONSTRAINT json_check CHECK (valid_json(VALUE));
CREATE FUNCTION get_key(key text, json_raw text) RETURNS json
LANGUAGE plv8 IMMUTABLE STRICT
AS $$
var val = JSON.parse(json_raw)[key];
var ret = {};
ret[key] = val;
return JSON.stringify(ret);
$$;
CREATE TABLE jsononly (
data json
);
COPY jsononly (data) FROM stdin;
-- Call twice to test the function cache.
SELECT get_key('ok', data) FROM jsononly;
get_key
-------------
{"ok":true}
(1 row)

SELECT get_key('ok', data) FROM jsononly;
get_key
-------------
{"ok":true}
(1 row)

0 comments on commit 564edaf

Please sign in to comment.