Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fgodino-milu committed Jan 16, 2025
2 parents 9aff673 + d6b981b commit bdd287c
Show file tree
Hide file tree
Showing 34 changed files with 349 additions and 160 deletions.
4 changes: 2 additions & 2 deletions .buildconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PG_VERSION=16.4
SDK_VERSION=3.1.72.3bi
WASI_SDK_VERSION=24.0.4
SDK_VERSION=3.1.74.2bi
WASI_SDK_VERSION=24.0.5
SDKROOT=/opt/python-wasm-sdk
5 changes: 5 additions & 0 deletions .changeset/afraid-wolves-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Improvements to parsing results received from pg
5 changes: 5 additions & 0 deletions .changeset/chilled-dolphins-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Fixed PGliteWorkerOptions type
5 changes: 5 additions & 0 deletions .changeset/late-forks-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Fix the return type of the `.transaction` method
5 changes: 5 additions & 0 deletions .changeset/lovely-melons-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Export the base filesystem to enable creating custom file systems. NOTE: This is a work-in-progress API, it is not stable, and may change significantly in future!
5 changes: 5 additions & 0 deletions .changeset/soft-starfishes-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Add affectedRows for COPY command
5 changes: 5 additions & 0 deletions .changeset/sweet-eagles-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Removes postgis extension which leads to a smaller build of the package
5 changes: 5 additions & 0 deletions .changeset/tasty-apples-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite-repl': patch
---

Bump versions of React, React DOM, and related testing libraries to v19 on pglite-repl. The PGlite REPL now supports React v18 and v19 projects.
5 changes: 5 additions & 0 deletions .changeset/tough-wombats-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite-react': patch
---

Bump versions of React, React DOM, and related testing libraries to v19 on pglite-react. pglite-react now supports React v18 and v19 projects.
5 changes: 5 additions & 0 deletions .changeset/twenty-eagles-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Refactor the protocol message parse code to be simpler and easer to follow
5 changes: 5 additions & 0 deletions .changeset/weak-pigs-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite-vue': patch
---

Fix Vue useLiveQuery to allow no parameters to be provided
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ jobs:
issues: write # to post issue comments (changesets/action)
pull-requests: write # to create pull request (changesets/action)
name: Make a PR or publish
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs: [build-wasm-postgres]
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_wasm_postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
OBJDUMP: true
contrib: contrib
extra: extra
EXTRA_EXT: vector postgis
EXTRA_EXT: vector

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trigger_buildkite_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
build:
name: Build Docker image
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- name: Trigger a Buildkite Build on Push using v2.0.0
uses: buildkite/[email protected]
Expand Down
5 changes: 1 addition & 4 deletions cibuild/linkweb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pushd src/backend
# -sSINGLE_FILE => Uncaught SyntaxError: Cannot use 'import.meta' outside a module (at postgres.html:1:6033)
# -sENVIRONMENT=web => XHR

export EMCC_WEB="-sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1"
export EMCC_WEB="-sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sENVIRONMENT=node,web"

if ${PGES6:-true}
then
Expand Down Expand Up @@ -233,6 +233,3 @@ echo "
"




24 changes: 15 additions & 9 deletions cibuild/sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ fi

if [ -f $SDKROOT/VERSION ]
then
echo "Using installed sdk from $SDKROOT"
echo "Using tested sdk from $SDKROOT"
else
echo "Installing sdk to $SDKROOT"
SDK_ARCHIVE=${SDK_ARCHIVE:-python3.13-wasm-sdk-Ubuntu-22.04.tar.lz4}
WASI_SDK_ARCHIVE=${WASI_SDK_ARCHIVE:-python3.13-wasi-sdk-Ubuntu-22.04.tar.lz4}
if $CI
if [ -d $SDKROOT/emsdk ]
then
echo "if sdk fails here, check .yml files and https://github.com/pygame-web/python-wasm-sdk releases"
echo "Using installed sdk from $SDKROOT"
else
echo "Installing sdk to $SDKROOT"
SDK_ARCHIVE=${SDK_ARCHIVE:-python3.13-wasm-sdk-Ubuntu-22.04.tar.lz4}
WASI_SDK_ARCHIVE=${WASI_SDK_ARCHIVE:-python3.13-wasi-sdk-Ubuntu-22.04.tar.lz4}
if $CI
then
echo "if sdk fails here, check .yml files and https://github.com/pygame-web/python-wasm-sdk releases"
fi
echo https://github.com/pygame-web/python-wasm-sdk/releases/download/$SDK_VERSION/$SDK_ARCHIVE
curl -sL --retry 5 https://github.com/pygame-web/python-wasm-sdk/releases/download/$SDK_VERSION/$SDK_ARCHIVE | tar xvP --use-compress-program=lz4 | pv -p -l -s 46000 >/dev/null
echo https://github.com/pygame-web/python-wasi-sdk/releases/download/$WASI_SDK_VERSION/$WASI_SDK_ARCHIVE
Expand Down Expand Up @@ -71,7 +75,7 @@ fi
int main(int argc, char**arv){
#if defined(__EMSCRIPTEN__)
# if defined(PYDK_STATIC)
# if defined(__PYDK__)
printf("pydk" " %d.%d.%d\n",__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__);
# else
printf("emsdk" " %d.%d.%d\n",__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__);
Expand All @@ -96,11 +100,13 @@ int main(int argc, char**arv){
}
END

EMCC_TRACE=true DEBUG_PATTERN=* ${SDKROOT}/emsdk/upstream/emscripten/emcc -sASSERTIONS=0 -sGLOBAL_BASE=32B -o hello_em.html /tmp/sdk/hello_em.c
EMCC_TRACE=true DEBUG_PATTERN=* ${SDKROOT}/emsdk/upstream/emscripten/emcc -sASSERTIONS=0 -sENVIRONMENT=node,web -sGLOBAL_BASE=32B -o hello_em.html /tmp/sdk/hello_em.c
$SDKROOT/emsdk/node/*.*.*64bit/bin/node hello_em.js
$SDKROOT/emsdk/node/*.*.*64bit/bin/node hello_em.js |grep ^pydk > $SDKROOT/VERSION || exit 80
rm hello_em.js hello_em.wasm

python3 -E ${SDKROOT}/emsdk/upstream/emscripten/emcc.py -O2 -g3 -sENVIRONMENT=node -sGLOBAL_BASE=32B $ALL -o hello_em.js /tmp/sdk/hello_em.c
python3 -E ${SDKROOT}/emsdk/upstream/emscripten/emcc.py -O2 -g3 -sENVIRONMENT=node,web -sGLOBAL_BASE=32B $ALL -o hello_em.js /tmp/sdk/hello_em.c
$SDKROOT/emsdk/node/*.*.*64bit/bin/node hello_em.js
$SDKROOT/emsdk/node/*.*.*64bit/bin/node hello_em.js |grep ^emsdk >> $SDKROOT/VERSION || exit 84

rm hello_em.*
Expand Down
8 changes: 7 additions & 1 deletion docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ We have a number of examples showing how to use PGlite along with its capabiliti
- <a href="./examples/opfs.html" target="_blank">OPFS VFS</a><br>
An example demonstrating the [OPFS Access Handle Pool VFS](./docs/filesystems.md#opfs-ahp-fs).

- <a href="./examples/copy.html" target="_blank">PL/PGSQL</a><br>
- <a href="./examples/plpgsql.html" target="_blank">PL/PGSQL</a><br>
Demonstration of PGlite's support for Postgres's built-in SQL procedural language extension "PL/PGSQL".

- <a href="./examples/vector.html" target="_blank">Extension: `pgvector`</a><br>
An example showing how to use [pgvector](https://github.com/pgvector/pgvector) with PGlite.

- <a href="./examples/worker.html" target="_blank">Multi Tab Worker</a><br>
Demonstration of the multi tab worker, enabling multiple browser tabs to share a PGlite database.

- <a href="./examples/fts.html" target="_blank">FTS</a><br>
An example showing how to use Full Text Search (FTS) with PGlite.

- <a href="./examples/pg_dump.html" target="_blank">pg_dump</a><br>
An example showing how to use the `pg_dump` tool with PGlite.
12 changes: 6 additions & 6 deletions packages/pglite-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@
"@electric-sql/pglite": "workspace:*",
"@eslint-react/eslint-plugin": "^1.14.3",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.0.1",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"@testing-library/react": "^16.1.0",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react": "^4.3.2",
"eslint-plugin-react-compiler": "0.0.0-experimental-9ed098e-20240725",
"globals": "^15.11.0",
"jsdom": "^24.1.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"vitest": "^2.1.2"
},
"peerDependencies": {
"@electric-sql/pglite": "workspace:^",
"react": "^18.0.0"
"react": "^18.0.0 || ^19.0.0 || ^19.0.0-rc"
}
}
2 changes: 1 addition & 1 deletion packages/pglite-react/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function useLiveQueryImpl<T = { [key: string]: unknown }>(
): Omit<LiveQueryResults<T>, 'affectedRows'> | undefined {
const db = usePGlite()
const paramsRef = useRef(params)
const liveQueryRef = useRef<LiveQuery<T> | undefined>()
const liveQueryRef = useRef<LiveQuery<T> | undefined>(undefined)
let liveQuery: LiveQuery<T> | undefined
let liveQueryChanged = false
if (!(typeof query === 'string') && !(query instanceof Promise)) {
Expand Down
4 changes: 3 additions & 1 deletion packages/pglite-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ interface Props<T extends PGliteWithLive> {
db?: T
}

type PGliteProvider<T extends PGliteWithLive> = (props: Props<T>) => JSX.Element
type PGliteProvider<T extends PGliteWithLive> = (
props: Props<T>,
) => React.JSX.Element
type UsePGlite<T extends PGliteWithLive> = (db?: T) => T

interface PGliteProviderSet<T extends PGliteWithLive> {
Expand Down
8 changes: 4 additions & 4 deletions packages/pglite-repl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"@uiw/codemirror-themes": "^4.23.5",
"@uiw/react-codemirror": "^4.23.5",
"psql-describe": "^0.1.5",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"peerDependencies": {
"@electric-sql/pglite": "workspace:^"
Expand All @@ -64,8 +64,8 @@
"devDependencies": {
"@electric-sql/pglite": "workspace:^",
"@types/node": "^20.16.11",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react": "^4.3.2",
"eslint-plugin-react-compiler": "0.0.0-experimental-9ed098e-20240725",
"eslint-plugin-react-hooks": "^4.6.2",
Expand Down
5 changes: 1 addition & 4 deletions packages/pglite-repl/src/Repl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,7 @@ export function Repl({
`}
style={styles}
>
<div
className="PGliteRepl-output"
ref={(ref) => (outputRef.current = ref)}
>
<div className="PGliteRepl-output" ref={outputRef}>
{loading && <div className="PGliteRepl-loading-msg">Loading...</div>}
{output.map((response) => (
<div key={`${response.query}-${response.time}`}>
Expand Down
12 changes: 5 additions & 7 deletions packages/pglite-vue/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function useLiveQueryImpl<T = { [key: string]: unknown }>(

const querySource = typeof query === 'string' ? ref(query) : query
const paramsSources = !params
? [ref(params)]
? []
: Array.isArray(params)
? params.map(ref)
: [params]
: [ref(params)]

const keySource = typeof key === 'string' ? ref(key) : key

Expand All @@ -68,13 +68,11 @@ function useLiveQueryImpl<T = { [key: string]: unknown }>(

const query = isRef(querySource) ? unref(querySource) : querySource()

const paramVals = isRef(params)
? unref(params)
const paramVals = Array.isArray(params)
? params.map((p) => (typeof p === 'function' ? p() : unref(p)))
: typeof params === 'function'
? params()
: Array.isArray(params)
? params.map(unref)
: [params]
: unref(params)

const key = isRef(keySource) ? keySource.value : keySource?.()

Expand Down
29 changes: 29 additions & 0 deletions packages/pglite-vue/test/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@ describe('hooks', () => {
`)
})

it('updates when query without parameters is provided', async () => {
const { useLiveQuery } = await import('../src')
await db.exec(`INSERT INTO test (name) VALUES ('test1');`)

const result = useLiveQuery('SELECT * FROM test;')

await flushPromises()
expect(result?.rows?.value).toEqual([
{
id: 1,
name: 'test1',
},
])

await db.exec(`INSERT INTO test (name) VALUES ('test2');`)

await flushPromises()
expect(result?.rows?.value).toEqual([
{
id: 1,
name: 'test1',
},
{
id: 2,
name: 'test2',
},
])
})

it('updates when query parameter ref changes', async () => {
const { useLiveQuery } = await import('../src')
await db.exec(`INSERT INTO test (name) VALUES ('test1'),('test2');`)
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite-vue/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
// @ts-ignore type mismsatch but works?
plugins: [vue()],
test: {
name: 'pglite-react',
name: 'pglite-vue',
dir: './test',
watch: false,
environment: 'jsdom',
Expand Down
Loading

0 comments on commit bdd287c

Please sign in to comment.