Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmd-azeez committed Mar 24, 2024
1 parent 7112e85 commit dece059
Show file tree
Hide file tree
Showing 3 changed files with 662 additions and 10 deletions.
35 changes: 27 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
# pg_extism

## Run Examples:
**Note**: This is an experimental SDK.

## Getting started
Make sure [`plv8`](https://github.com/plv8/plv8) is installed:
```sql
create extension plv8;
```

Generate sql functions:
```
npm install
npm run build
```

node --experimental-wasi-unstable-preview1 ./examples/node.js wasm/config.wasm
Now you can find a `index.sql` in `dist`. Run the sql script in your database.
This gives you two functions: `extism_create_plugin`, `extism_call`.

deno run -A ./examples/deno.js ./wasm/config.wasm
## Use pg_extism

bun run ./examples/node.js wasm/config.wasm
Assume you have a table called `plugins`:
```sql
CREATE TABLE public.plugins (
id int4 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL,
"data" bytea NULL,
"name" varchar NULL,
CONSTRAINT plugins_pk PRIMARY KEY (id)
);
```

## Update `extism-kernel.wasm`:
We are shipping an embedded kernel in base64 form in plugin.ts. To update it, you can run these commands:
Insert a few plugins into the table. And then call:

```
select extism_call(data, 'count_vowels', 'Hello World!') from plugins where id = 2;
```
make update-kernel
```

**Note:** this assumes the plugin with id `2` has a function called `count_vowels`. You can find the plugin [here](https://github.com/extism/plugins/releases).
Loading

0 comments on commit dece059

Please sign in to comment.