Skip to content

Commit

Permalink
Merge branch 'r3.0alpha' of https://github.com/JerrySievert/plv8 into…
Browse files Browse the repository at this point in the history
… r3.0alpha
  • Loading branch information
JerrySievert committed Dec 10, 2018
2 parents 5fc4e80 + b298b64 commit 2340595
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 98 deletions.
8 changes: 8 additions & 0 deletions Changes
@@ -1,5 +1,13 @@
Revision history for plv8

3.0alpha
- update to v8 7.0
- add Bigint support
- add BigInt64Array support

2.3.9 2018-12-09
- work around pg11 forced filename endings

2.3.8 2018-09-28
- earlier cleanup of spi
- support in v8 of xcode 10
Expand Down
14 changes: 7 additions & 7 deletions META.json
Expand Up @@ -2,7 +2,7 @@
"name": "plv8",
"abstract": "A procedural language in JavaScript powered by V8",
"description": "plv8 is a trusted procedural language that is safe to use, fast to run and easy to develop.",
"version": "2.3.9",
"version": "3.0alpha",
"maintainer": [
"Jerry Sievert <code@legitimatesounding.com>"
],
Expand All @@ -23,21 +23,21 @@
},
"provides": {
"plv8": {
"file": "plv8--2.3.9.sql",
"file": "plv8--3.0alpha.sql",
"docfile": "docs/PGXN.md",
"version": "2.3.9",
"version": "3.0alpha",
"abstract": "A procedural language in JavaScript"
},
"plcoffee": {
"file": "plcoffee--2.3.9.sql",
"file": "plcoffee--3.0alpha.sql",
"docfile": "docs/PGXN.md",
"version": "2.3.9",
"version": "3.0alpha",
"abstract": "A procedural language in CoffeeScript"
},
"plls": {
"file": "plls--2.3.9.sql",
"file": "plls--3.0alpha.sql",
"docfile": "docs/PGXN.md",
"version": "2.3.9",
"version": "3.0alpha",
"abstract": "A procedural language in LiveScript"
}
},
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Expand Up @@ -7,7 +7,7 @@
# structure in v8 which may be different from version to another, but user
# can specify the v8 version by AUTOV8_VERSION, too.
#-----------------------------------------------------------------------------#
AUTOV8_VERSION = 6.4.388.40
AUTOV8_VERSION = 7.0.276.20
AUTOV8_DIR = build/v8
AUTOV8_OUT = build/v8/out.gn/x64.release/obj
AUTOV8_DEPOT_TOOLS = build/depot_tools
Expand All @@ -32,7 +32,7 @@ $(AUTOV8_DEPOT_TOOLS):
cd build; git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

$(AUTOV8_DIR): $(AUTOV8_DEPOT_TOOLS)
cd build; fetch v8; cd v8; git checkout $(AUTOV8_VERSION); gclient sync ; cd build/config ; git cherry-pick 4287a0d364541583a50cc91465330251460d489a ; cd ../.. ; tools/dev/v8gen.py $(PLATFORM) -- $(V8_OPTIONS)
cd build; fetch v8; cd v8; git checkout $(AUTOV8_VERSION); gclient sync ; tools/dev/v8gen.py $(PLATFORM) -- $(V8_OPTIONS)

$(AUTOV8_OUT)/third_party/icu/common/icudtb.dat:

Expand All @@ -47,6 +47,10 @@ ifdef EXECUTION_TIMEOUT
CCFLAGS += -DEXECUTION_TIMEOUT
endif

ifdef BIGINT_GRACEFUL
CCFLAGS += -DBIGINT_GRACEFUL
endif

CCFLAGS += -I$(AUTOV8_DIR)/include -I$(AUTOV8_DIR)
# We're gonna build static link. Rip it out after include Makefile
SHLIB_LINK := $(filter-out -lv8, $(SHLIB_LINK))
Expand Down
10 changes: 8 additions & 2 deletions Makefile.shared
Expand Up @@ -12,7 +12,7 @@
# 'make' will download v8 and build, then statically link to it.
#
#-----------------------------------------------------------------------------#
PLV8_VERSION = 2.3.9
PLV8_VERSION = 3.0alpha

PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
Expand Down Expand Up @@ -43,6 +43,12 @@ ifndef DISABLE_DIALECT
REGRESS += dialect
endif

ifndef BIGINT_GRACEFUL
REGRESS += bigint
else
REGRESS += bigint_graceful
endif

SHLIB_LINK += -lv8
ifdef V8_OUTDIR
SHLIB_LINK += -L$(V8_OUTDIR)
Expand All @@ -60,7 +66,7 @@ endif
# for older g++ (e.g. 4.6.x), which do not support c++11
#OPTFLAGS = -O2 -std=gnu++0x -fno-rtti

OPTFLAGS = -O2 -std=c++11 -fno-rtti
OPTFLAGS = -std=c++11 -fno-rtti -O2

CCFLAGS = -Wall $(OPTFLAGS) $(OPT_ENABLE_DEBUGGER_SUPPORT)

Expand Down
21 changes: 5 additions & 16 deletions docs/BUILDING.md
Expand Up @@ -8,15 +8,16 @@ Building PLV8 for MacOS or Linux has some specific requirements:
* g++ or clang++
* Python 2 (for v8)
* pgk-config (linux only for v8)
* libc++-dev (linux only)

### Downloading Source

Downloading the source code is very straightforward:

```
$ wget https://github.com/plv8/plv8/archive/v2.3.3.tar.gz
$ tar -xvzf v2.3.3.tar.gz
$ cd plv8-2.3.3
$ wget https://github.com/plv8/plv8/archive/v2.3.8.tar.gz
$ tar -xvzf v2.3.8.tar.gz
$ cd plv8-2.3.8
$ make
```

Expand All @@ -28,13 +29,7 @@ Building is simple:
$ make
```

This will download `v8` and compile it as well. If you have a shared modern
version of `v8` available (6.4.388.40 or above), you can compile it against a
shared module:

```
$ make -f Makefile.shared
```
This will download `v8` and compile it as well.

| Note: If you have multiple versions of PostgreSQL installed like 9.5 and 9.6, Plv8 will only be built for PostgreSQL 9.6. This is because make calls pg_config to get the version number, which will always be the latest version installed. If you need to build Plv8 for PostgreSQL 9.5 while you have 9.6 installed pass make the PG_CONFIG variable to your 9.5 version of pg_config. This works for `make`, `make -f Makefile.shared`, and `make install`. For example in Ubuntu:

Expand Down Expand Up @@ -172,9 +167,3 @@ This will build and package the extension for installation.
To install, you simply need to `unzip` the file created. The name will depend
on the version of PLV8 and the version of Postgres. An example is
`plv8-2.3.1-postgresql-10-x64.zip`.

### TODO

* Generate configuration files
* Generate control files
* Generate sql files
4 changes: 2 additions & 2 deletions docs/README.md
Expand Up @@ -4,7 +4,7 @@ PLV8 is a _trusted_ Javascript language extension for PostgreSQL. It can be
used for _stored procedures_, _triggers_, etc.

PLV8 works with most versions of Postgres, but works best with `9.1` and above,
including `10.0` and `10.1`.
including `10.0` and `11`.

## Installing PLV8

Expand Down Expand Up @@ -36,7 +36,7 @@ As of PLV8 version `2.3.3`, you can use upgrade scripts to upgrade your
installation from any verion higher than `1.5.0`:

```
=# ALTER EXTENSION plv8 UPDATE TO `2.3.3`;
=# ALTER EXTENSION plv8 UPDATE TO `2.3.8`;
```

Note that until the database has been restarted, the old version of PLV8 will
Expand Down
26 changes: 26 additions & 0 deletions expected/bigint.out
@@ -0,0 +1,26 @@
-- BigInt precedures
-- a BigInt that will work on any value
CREATE OR REPLACE FUNCTION bigint_working(val BIGINT)
RETURNS BIGINT AS $$
return val - 1n;
$$ LANGUAGE plv8 STABLE STRICT;
SELECT bigint_working(9223372036854775807);
bigint_working
---------------------
9223372036854775806
(1 row)

SELECT bigint_working(32);
bigint_working
----------------
31
(1 row)

-- a BigInt that will fail on any value
CREATE OR REPLACE FUNCTION bigint_failing(val BIGINT)
RETURNS BIGINT AS $$
return val - 1;
$$ LANGUAGE plv8 STABLE STRICT;
SELECT bigint_failing(9223372036854775807);
ERROR: TypeError: Cannot mix BigInt and other types, use explicit conversions
CONTEXT: bigint_failing() LINE 2: return val - 1;
31 changes: 31 additions & 0 deletions expected/bigint_graceful.out
@@ -0,0 +1,31 @@
-- BigInt precedures
-- a BigInt that will work on BigInt
CREATE OR REPLACE FUNCTION bigint_graceful1(val BIGINT)
RETURNS BIGINT AS $$
return val - 1n;
$$ LANGUAGE plv8 STABLE STRICT;
SELECT bigint_graceful1(9223372036854775807);
bigint_graceful1
---------------------
9223372036854775806
(1 row)

-- this will fail
SELECT bigint_graceful1(32);
ERROR: TypeError: Cannot mix BigInt and other types, use explicit conversions
CONTEXT: bigint_graceful1() LINE 2: return val - 1n;
-- a BigInt that will fail on BigInt
CREATE OR REPLACE FUNCTION bigint_graceful2(val BIGINT)
RETURNS BIGINT AS $$
return val - 1;
$$ LANGUAGE plv8 STABLE STRICT;
SELECT bigint_graceful2(32);
bigint_graceful2
------------------
31
(1 row)

-- this will fail
SELECT bigint_graceful2(9223372036854775807);
ERROR: TypeError: Cannot mix BigInt and other types, use explicit conversions
CONTEXT: bigint_graceful2() LINE 2: return val - 1;
8 changes: 4 additions & 4 deletions expected/window.out
@@ -1,5 +1,5 @@
-- window functions
CREATE FUNCTION js_row_number() RETURNS int8 AS $$
CREATE FUNCTION js_row_number() RETURNS numeric AS $$
var winobj = plv8.get_window_object();
return winobj.get_current_position() + 1;
$$ LANGUAGE plv8 WINDOW;
Expand All @@ -21,14 +21,14 @@ CREATE FUNCTION __js_rank_up(winobj internal, up_callback internal) RETURNS void
winobj.set_partition_local(context);
return context;
$$ LANGUAGE plv8;
CREATE FUNCTION js_rank() RETURNS int8 AS $$
CREATE FUNCTION js_rank() RETURNS numeric AS $$
var winobj = plv8.get_window_object();
var context = plv8.find_function("__js_rank_up")(winobj, function(context){
context.rank = winobj.get_current_position() + 1;
});
return context.rank;
$$ LANGUAGE plv8 WINDOW;
CREATE FUNCTION js_dense_rank() RETURNS int8 AS $$
CREATE FUNCTION js_dense_rank() RETURNS numeric AS $$
var winobj = plv8.get_window_object();
var context = plv8.find_function("__js_rank_up")(winobj, function(context){
context.rank++;
Expand Down Expand Up @@ -61,7 +61,7 @@ CREATE FUNCTION js_cume_dist() RETURNS float AS $$
winobj.set_partition_local(context);
return context.rank / totalrows;
$$ LANGUAGE plv8 WINDOW;
CREATE FUNCTION js_ntile(nbuckets int8) RETURNS int AS $$
CREATE FUNCTION js_ntile(nbuckets numeric) RETURNS int AS $$
var winobj = plv8.get_window_object();
var context = winobj.get_partition_local() || {};

Expand Down

0 comments on commit 2340595

Please sign in to comment.