Permalink
Browse files

v20091101a

by Hitoshi Harada
  • Loading branch information...
0 parents commit 04fbab6ed71e59b470b6a959c21acaa1548db1f9 kyz@jcode.uphsurabaya.ac.id committed Nov 2, 2009
Showing with 787 additions and 0 deletions.
  1. +24 −0 Makefile
  2. +49 −0 README
  3. BIN archive/plv8.20091101.tgz
  4. +696 −0 plv8.cc
  5. +18 −0 plv8.h
@@ -0,0 +1,24 @@
+
+PGDIR = ../postgresql
+V8DIR = ../v8-1.2
+
+PROG = plv8
+OBJS = plv8.o
+CC = g++
+#CFLAGS = -g -Wall
+CFLAGS = -O2 -Wall -fPIC
+INCS = -I$(PGDIR)/src/include -I$(V8DIR)/include
+LIBS = -lv8
+
+all: $(PROG)
+
+$(PROG):$(OBJS)
+ $(CC) $(LIBS) -shared -o $@.so $^
+# $(V8DIR)/libv8_g.a
+
+.c.o:
+ $(CC) $(CFLAGS) $(INCS) -o $@ -c $<
+
+clean:
+ rm -rf $(OBJS)
+ rm -rf $(PROG).so
@@ -0,0 +1,49 @@
+plv8 version 2009/11/01
+
+* OVERVIEW
+
+plv8 is shared library that provides a PostgreSQL procedual language powered by V8 JavaScript Engine. With this program you can write in JavaScript your function that is callable from SQL.
+
+
+* REQUIREMENT
+plv8 requires:
+PG: version 8.4.x (maybe older are allowed)
+V8: version 1.2
+g++ and all tools that PG and V8 requires to be built.
+
+
+* INSTALL
+
+** Get PostgreSQL and V8 source
+PG: http://www.postgresql.org/ftp/source/
+v8: http://code.google.com/p/v8/wiki/Source
+
+Build both of them. Note v8 build option requires mode=release and library=shared. Edit Makefile in plv8 directory so that $(PGDIR) and $(V8DIR) point their directories and type "make". If your prompt doesn't say anything and you can find plv8.so, that's all.
+
+
+* TEST
+
+Copy plv8.so into $(PGHOME)/lib and libv8.so from v8 directory into some path that PostgreSQL can read as a library such like /usr/lib/. Then type below SQL in your psql;
+CREATE FUNCTION plv8_call_handler() RETURNS language_handler AS '$libdir/plv8' LANGUAGE C;
+CREATE FUNCTION plv8_call_validator(Oid) RETURNS void AS '$libdir/plv8' LANGUAGE C;
+CREATE LANGUAGE plv8 HANDLER plv8_call_handler VALIDATOR plv8_call_validator;
+
+-- create js function
+CREATE OR REPLACE FUNCTION plv8_test(keys text[], vals text[]) RETURNS text AS $$
+var o = {};
+for(var i=0; i<keys.length; i++){
+ o[keys[i]] = vals[i];
+}
+return JSON.stringify(o);
+$$ LANGUAGE plv8 IMMUTABLE STRICT;
+
+-- test
+SELECT plv8_test(ARRAY['name', 'age'], ARRAY['Tom', '29']);
+
+* CAVEATS
+- This is WIP version.
+- Tested on only CentOS 5 (x86), PostgreSQL 8.4 (8.5devel) and v8 1.2.
+- There's no interface to call SPI.
+- You must specify argument names in function declarations.
+- 1-dim array can be put as arguments. Multi dimension array is not supported.
+- And many, many bugs...
Binary file not shown.
Oops, something went wrong.

0 comments on commit 04fbab6

Please sign in to comment.