Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Jul 25, 2024
1 parent 97abee5 commit 4ec30a7
Show file tree
Hide file tree
Showing 19 changed files with 1,504 additions and 494 deletions.
3 changes: 2 additions & 1 deletion cibuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ END

# workaround no "locale -a" for Node.
# this is simply the minimal result a popen call would give.
cat > ${PGROOT}/locale <<END
mkdir -p ${PGROOT}/etc/postgresql
cat > ${PGROOT}/etc/postgresql/locale <<END
C
C.UTF-8
POSIX
Expand Down
123 changes: 45 additions & 78 deletions cibuild/linkweb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ pushd src/backend
# https://github.com/llvm/llvm-project/issues/50623


echo " ---------- building web test PREFIX=$PGROOT ------------"
du -hs ${WEBROOT}/libpg?.*
echo " ---------- building web test PREFIX=$PGROOT ------------"
du -hs ${WEBROOT}/libpg?.*

PG_O="../../src/fe_utils/string_utils.o ../../src/common/logging.o \
PG_O="../../src/fe_utils/string_utils.o ../../src/common/logging.o \
$(find . -type f -name "*.o" \
| grep -v ./utils/mb/conversion_procs \
| grep -v ./replication/pgoutput \
Expand All @@ -74,48 +74,15 @@ pushd src/backend
../../src/common/libpgcommon_srv.a ../../src/port/libpgport_srv.a"



if false
then
# PG_L="$PG_L -L../../src/interfaces/ecpg/ecpglib ../../src/interfaces/ecpg/ecpglib/libecpg.so /tmp/pglite/lib/postgresql/libduckdb.so"
PG_L="$PG_L -L../../src/interfaces/ecpg/ecpglib ../../src/interfaces/ecpg/ecpglib/libecpg.so /tmp/libduckdb.so -lstdc++"
else
PG_L="$PG_L -L../../src/interfaces/ecpg/ecpglib ../../src/interfaces/ecpg/ecpglib/libecpg.so"
PG_L="../../src/common/libpgcommon_srv.a ../../src/port/libpgport_srv.a ../.././src/interfaces/libpq/libpq.a"

fi

# ../../src/common/libpgcommon_shlib.a"
# ./src/common/libpgcommon.a: binary file matches
# ./src/common/libpgcommon_shlib.a: binary file matches
# error: undefined symbol: fsync_pgdata (referenced by root reference (e.g. compiled C/C++ code))
# error: undefined symbol: get_restricted_token (referenced by root reference (e.g. compiled C/C++ code))
# error: undefined symbol: pg_malloc_extended (referenced by root reference (e.g. compiled C/C++ code))
# error: undefined symbol: pg_realloc (referenced by root reference (e.g. compiled C/C++ code))
# error: undefined symbol: pg_strdup (referenced by root reference (e.g. compiled C/C++ code))
# error: undefined symbol: simple_prompt (referenced by root reference (e.g. compiled C/C++ code))



## \
# /opt/python-wasm-sdk/devices/emsdk/usr/lib/libxml2.a \
# /opt/python-wasm-sdk/devices/emsdk/usr/lib/libgeos.a \
# /opt/python-wasm-sdk/devices/emsdk/usr/lib/libgeos_c.a \
# /opt/python-wasm-sdk/devices/emsdk/usr/lib/libproj.a"

# /data/git/pglite-build/pglite/postgres/libgeosall.so
# /data/git/pglite-build/pglite/postgres/libduckdb.so"


# ? -sLZ4=1 -sENVIRONMENT=web
# ? -sLZ4=1 -sENVIRONMENT=web
# -sSINGLE_FILE => Uncaught SyntaxError: Cannot use 'import.meta' outside a module (at postgres.html:1:6033)
# -sENVIRONMENT=web => XHR
EMCC_WEB="-sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1"

if ${PGES6:-true}
then
# es6
MODULE="-g0 -Os -sMODULARIZE=1 -sEXPORT_ES6=1 -sEXPORT_NAME=Module --shell-file ${GITHUB_WORKSPACE}/tests/repl.html"
MODULE="-g0 -O2 -sMODULARIZE=1 -sEXPORT_ES6=1 -sEXPORT_NAME=Module --shell-file ${GITHUB_WORKSPACE}/tests/repl.html"
else
# local debug fast build
MODULE="-g3 -O0 -sMODULARIZE=0 -sEXPORT_ES6=0 --shell-file ${GITHUB_WORKSPACE}/tests/repl.html"
Expand Down Expand Up @@ -155,44 +122,44 @@ rm ${PGROOT}/lib/postgresql/utf8_and*.so
echo 'localhost:5432:postgres:postgres:password' > pgpass


if [ -f ${PGROOT}/symbols ]
then
# _main,_getenv,_setenv,_interactive_one,_interactive_write,_interactive_read,_pg_initdb,_pg_shutdown

#not yet
#_emscripten_copy_from
#_emscripten_copy_to
#_emscripten_copy_to_end


cat > exports <<END
___cxa_throw
_main
_main_repl
_pg_repl_raf
_getenv
_setenv
_interactive_one
_interactive_write
_interactive_read
_pg_initdb
_pg_shutdown
_lowerstr
END
cat ${PGROOT}/symbols | sort | uniq \
| grep -v _plpgsql_ \
| grep -v duckdb \
| grep -v ^_halfvec_l2_normalize \
| grep -v ^_l2_normalize \
| grep -v ^_sparsevec_l2_normalize \
| grep -v ^_1 \
| grep -v ^_\< \
| grep -v ^_env$ \
>> exports
cat exports > ${GITHUB_WORKSPACE}/patches/exports
else
#if [ -f ${PGROOT}/symbols ]
#then
# # _main,_getenv,_setenv,_interactive_one,_interactive_write,_interactive_read,_pg_initdb,_pg_shutdown

##not yet
##_emscripten_copy_from
##_emscripten_copy_to
##_emscripten_copy_to_end


# cat > exports <<END
#___cxa_throw
#_main
#_main_repl
#_pg_repl_raf
#_getenv
#_setenv
#_interactive_one
#_interactive_write
#_interactive_read
#_pg_initdb
#_pg_shutdown
#_lowerstr
#END
# cat ${PGROOT}/symbols | sort | uniq \
# | grep -v _plpgsql_ \
# | grep -v duckdb \
# | grep -v ^_halfvec_l2_normalize \
# | grep -v ^_l2_normalize \
# | grep -v ^_sparsevec_l2_normalize \
# | grep -v ^_1 \
# | grep -v ^_\< \
# | grep -v ^_env$ \
# >> exports
# cat exports > ${GITHUB_WORKSPACE}/patches/exports
#else
cat ${GITHUB_WORKSPACE}/patches/exports >> exports
fi
#fi

# copyFrom,copyTo,copyToEnd

Expand All @@ -203,6 +170,7 @@ emcc $EMCC_WEB -fPIC -sMAIN_MODULE=2 \
-lnodefs.js -lidbfs.js \
-sEXPORTED_RUNTIME_METHODS=FS,setValue,getValue,UTF8ToString,stringToNewUTF8,stringToUTF8OnStack,ccall,cwrap,callMain \
-sEXPORTED_FUNCTIONS=@exports \
--preload-file ${PGROOT}/etc/postgresql/locale@${PGROOT}/etc/postgresql/locale \
--preload-file ${PGROOT}/share/postgresql@${PGROOT}/share/postgresql \
--preload-file ${PGROOT}/lib/postgresql@${PGROOT}/lib/postgresql \
--preload-file ${PGROOT}/password@${PGROOT}/password \
Expand All @@ -214,17 +182,16 @@ emcc $EMCC_WEB -fPIC -sMAIN_MODULE=2 \
mkdir -p ${WEBROOT}

cp -v postgres.* ${WEBROOT}/
#cp ${PGROOT}/lib/libecpg.so ${WEBROOT}/
cp ${PGROOT}/sdk/*.tar ${WEBROOT}/
for tarf in ${WEBROOT}/*.tar
do
gzip -f -9 $tarf
done


cp $GITHUB_WORKSPACE/{tests/vtx.js,patches/tinytar.min.js} ${WEBROOT}/
cp $GITHUB_WORKSPACE/{tests/vtx.js,patches/tinytar.min.js} ${WEBROOT}/

popd
popd

echo "
linkweb:end
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"pnpm":{"patchedDependencies":{"[email protected].0":"patches/[email protected].0.patch"}}}
{"pnpm":{"patchedDependencies":{"[email protected].1":"patches/[email protected].1.patch"}}}
2 changes: 1 addition & 1 deletion packages/pglite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"comlink": "^4.4.1",
"concurrently": "^8.2.2",
"http-server": "^14.1.1",
"pg-protocol": "^1.6.0",
"pg-protocol": "^1.6.1",
"playwright": "^1.42.1",
"prettier": "3.2.5",
"tinytar": "^0.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/scripts/bundle-wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function findAndReplaceInDir(
async function main() {
await fs.copyFile("./release/postgres.wasm", "./dist/postgres.wasm");
await fs.copyFile("./release/postgres.data", "./dist/postgres.data");
// await fs.copyFile("./release/postgres.so", "./dist/postgres.so");
await fs.copyFile("./release/postgres.js", "./dist/postgres.js");
await fs.copyFile("./release/vector.tar.gz", "./dist/vector.tar.gz");
await findAndReplaceInDir(
"./dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/src/extensionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tinyTar from "tinytar";
import { IN_NODE } from "./utils.js";
import type { PostgresMod } from "./postgres.js";
import type { PostgresMod } from "./postgresMod.js";

export async function loadExtensionBundle(
bundlePath: URL,
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/src/fs/idbfs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilesystemBase } from "./types.js";
import type { FS, PostgresMod } from "../postgres.js";
import type { FS, PostgresMod } from "../postgresMod.js";
import { PGDATA } from "./index.js";
import { dumpTar } from "./tarUtils.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/src/fs/memoryfs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilesystemBase } from "./types.js";
import type { PostgresMod, FS } from "../postgres.js";
import type { PostgresMod, FS } from "../postgresMod.js";
import { dumpTar } from "./tarUtils.js";

export class MemoryFS extends FilesystemBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/src/fs/nodefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "fs";
import * as path from "path";
import { FilesystemBase } from "./types.js";
import { PGDATA } from "./index.js";
import type { PostgresMod, FS } from "../postgres.js";
import type { PostgresMod, FS } from "../postgresMod.js";
import { dumpTar } from "./tarUtils.js";

export class NodeFS extends FilesystemBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/src/fs/tarUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tar, untar, type TarFile, REGTYPE, DIRTYPE } from "tinytar";
import { FS } from "../postgres.js";
import { FS } from "../postgresMod.js";
import { PGDATA } from "./index.js";

export async function dumpTar(FS: FS, dbname?: string): Promise<File | Blob> {
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/src/fs/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PostgresMod, FS } from "../postgres.js";
import type { PostgresMod, FS } from "../postgresMod.js";

export type FsType = "nodefs" | "idbfs" | "memoryfs";

Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/src/pglite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Mutex } from "async-mutex";
import PostgresModFactory, { type PostgresMod } from "./postgres.js";
import PostgresModFactory, { type PostgresMod } from "./postgresMod.js";
import { type Filesystem, parseDataDir, loadFs } from "./fs/index.js";
import { makeLocateFile } from "./utils.js";
import { parseResults } from "./parse.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ts-ignore
import PostgresModFactory from "../release/postgres.js";
// This file in placed in the build from ../release/postgres.js
import PostgresModFactory from "./postgres.js";

// Uses the types from @types/emscripten

Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/tests/pgvector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test("pgvector", async (t) => {
},
{
name: "vec",
dataTypeID: 12772,
dataTypeID: 12345,
},
{
name: "distance",
Expand Down
44 changes: 44 additions & 0 deletions packages/pglite/tests/plpgsql.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import test from "ava";
import { PGlite } from "../dist/index.js";

test("can create and call function", async (t) => {
const db = new PGlite();
await db.exec(`
CREATE EXTENSION IF NOT EXISTS plpgsql;
CREATE OR REPLACE FUNCTION test_func()
RETURNS TEXT AS $$
BEGIN
RETURN 'test';
END;
$$ LANGUAGE plpgsql;
`);

const res = await db.query("SELECT test_func();");
t.is(res.rows[0].test_func, "test");
});

test("can create and call complex function", async (t) => {
const db = new PGlite();
await db.exec(`
CREATE EXTENSION IF NOT EXISTS plpgsql;
CREATE OR REPLACE FUNCTION calculate_factorial(n INT) RETURNS INT AS $$
DECLARE
result INT := 1;
BEGIN
IF n < 0 THEN
RAISE EXCEPTION 'The input cannot be negative.';
ELSIF n = 0 OR n = 1 THEN
RETURN result;
ELSE
FOR i IN 2..n LOOP
result := result * i;
END LOOP;
RETURN result;
END IF;
END;
$$ LANGUAGE plpgsql;
`);

const res = await db.query("SELECT calculate_factorial(5) AS result;");
t.is(res.rows[0].result, 120);
});
3 changes: 2 additions & 1 deletion packages/pglite/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fileURLToPath } from "url";
const thisFile = fileURLToPath(new URL(import.meta.url));
const root = path.dirname(thisFile);

let replaceAssertPlugin = {
const replaceAssertPlugin = {
name: "replace-assert",
setup(build: any) {
// Resolve `assert` to a blank file
Expand All @@ -31,6 +31,7 @@ export default defineConfig({
},
clean: true,
format: ["esm"],
external: ["./postgres.js"],
esbuildOptions(options, context) {
options.inject = [
"src/polyfills/buffer.ts",
Expand Down
Loading

0 comments on commit 4ec30a7

Please sign in to comment.