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

Commit

Permalink
Several fixes and improvements by Itagaki Takahiro.
Browse files Browse the repository at this point in the history
There are incompatibilites in built-in functions and global variables.

  * Support PGXS to build the codes.
  * Added regression tests.
  * Support additional type conversions:
    - timestamp [with time zone]
    - date
    - record (input only)
    - oid
  * Logging function is renamed to print(elevel, ...). Acceptable elevels
    are DEBUG[1-5], LOG, INFO, NOTICE, and WARNING.  Use JavaScript
    exceptions (throw) to report errors; ERROR level are not allowed.
  * Query function is renamed to executeSql(sql). For SELECT statements,
    the returned value is an array of hashes. Each hash represents each
    record. Column names are mapped to hash keys.  For non-SELECT commands,
    the returned value is an integer that represents number of affected rows.
  * Trigger functions receives trigger conditions as function arguments:
    NEW, OLD, TG_NAME, TG_WHEN, TG_LEVEL, TG_OP, TG_RELID, TG_TABLE_NAME,
    TG_TABLE_SCHEMA, and TG_ARGV.
  * Support VARIADIC arguments.
  * Support unnamed arguments. They can be referred with 'arguments' or $N.
  * Fix error handling and exception handling. Postgre's errors (siglongjmp)
    are packed into C++ exceptions to invoke destructors properly,
    and extracted at the end of function.
  • Loading branch information
ItGacky committed Aug 23, 2010
1 parent 4a21d56 commit 30f2336
Show file tree
Hide file tree
Showing 10 changed files with 1,868 additions and 1,027 deletions.
39 changes: 30 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
all:
g++ -O2 -Wall -fPIC -I ../postgres/pgsql/src/include -I ../v8/include -o plv8.o -c plv8.cc
g++ -lv8 -shared -o plv8.so plv8.o
clean:
rm plv8.so plv8.o
distclean: clean
realclean: clean

.PHONY: all clean distclean realclean
V8DIR = ../v8

SRCS = plv8.cc plv8_type.cc
OBJS = $(SRCS:.cc=.o)
DATA_built = plv8.sql
DATA = uninstall_plv8.sql
SHLIB_LINK += -lv8
MODULE_big = plv8
REGRESS = plv8

CCFLAGS := $(filter-out -Wmissing-prototypes, $(CFLAGS))
CCFLAGS := $(filter-out -Wdeclaration-after-statement, $(CCFLAGS))

%.o : %.cc
g++ $(CCFLAGS) $(CPPFLAGS) -I $(V8DIR)/include -fPIC -c -o $@ $<

ifdef USE_PGXS
PGXS := $(shell pg_config --pgxs)
include $(PGXS)
else
subdir = contrib/plv8
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif

# remove dependency to libxml2 and libxslt
LIBS := $(filter-out -lxml2, $(LIBS))
LIBS := $(filter-out -lxslt, $(LIBS))

7 changes: 3 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plv8 is shared library that provides a PostgreSQL procedual language powered by
* REQUIREMENT
plv8 requires:
PG: version 8.4.x (maybe older are allowed)
V8: version 1.2
V8: version 2.3.8
g++ and all tools that PG and V8 requires to be built.


Expand All @@ -29,7 +29,7 @@ CREATE FUNCTION plv8_call_validator(Oid) RETURNS void AS '$libdir/plv8' LANGUAGE
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 $$
CREATE 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];
Expand All @@ -42,8 +42,7 @@ 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.
- Tested on only CentOS 5 (x86), PostgreSQL 8.4 (9.0devel) and v8 2.3.8.
- 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...
55 changes: 3 additions & 52 deletions download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,7 @@ cd $idir
#hg pull https://plv8js.googlecode.com/hg/
#hg push # for push to googlecode
#hg commit -u username@gmail.com -m "commit message"
g++ -O2 -Wall -fPIC -I ../postgres/pgsql/src/include -I ../v8/include -o plv8.o -c plv8.cc
g++ -lv8 -shared -o plv8.so plv8.o
ifile=/home/`whoami`/Software/PostgreSQL-9/lib/plv8.so
sudo rm -f $ifile
sudo ln -s $idir/plv8.so $ifile

echo '';
echo '======= testing PLV8'
echo 'DROP FUNCTION IF EXISTS plv8_call_handler() CASCADE; DROP FUNCTION plv8_call_validator(Oid) CASCADE;' | psql
echo "CREATE FUNCTION plv8_call_handler() RETURNS language_handler AS '/home/`whoami`/Software/PostgreSQL-9/lib/plv8' LANGUAGE C; CREATE FUNCTION plv8_call_validator(Oid) RETURNS void AS '/home/`whoami`/Software/PostgreSQL-9/lib/plv8' LANGUAGE C; CREATE LANGUAGE plv8 HANDLER plv8_call_handler VALIDATOR plv8_call_validator;" | psql

echo '';
echo '======= testing Function'
echo '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; ' | psql
echo "SELECT plv8_test(ARRAY['name', 'age'], ARRAY['Tom', '29']);" | psql

echo '';
echo '======= create test TABLE';
echo 'DROP TABLE IF EXISTS test CASCADE;' | psql
echo 'CREATE TABLE test ( za BIGSERIAL PRIMARY KEY, ztext TEXT );' | psql
echo "INSERT INTO test(ztext) VALUES( 'a'),( 'b'),( 'c');" | psql

echo '';
echo '======= testing SPI'
echo '
CREATE OR REPLACE FUNCTION testing123() RETURNS text AS $____$
var x = new SPI();
//return x.query("INSERT INTO test (ztext) VALUES( $$x$$ ) RETURNING * ");
return x.query("SELECT ztext FROM test");
$____$ LANGUAGE "plv8";
' | psql
echo 'SELECT testing123();' | psql

echo '';
echo '======= testing Trigger'
echo '
CREATE OR REPLACE FUNCTION testingT() RETURNS trigger AS $____$
var x = new TRIG();
var y = new LOG();
y.notice( "called from " + x.event() );
return; // harusnya mengembalikan sesuatu.. apa ya?
$____$ LANGUAGE "plv8";
' | psql
echo 'CREATE TRIGGER onDel1 AFTER DELETE ON test EXECUTE PROCEDURE testingT();' | psql
echo 'DELETE FROM test;' | psql

make USE_PGXS=1
make USE_PGXS=1 install
make USE_PGXS=1 installcheck
Loading

0 comments on commit 30f2336

Please sign in to comment.