-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7112e85
commit dece059
Showing
3 changed files
with
662 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
Oops, something went wrong.