splitgraph / seafowl

Analytical database for data-driven Web applications 🪶
https://seafowl.io
Apache License 2.0
397 stars 9 forks source link

Udf: example in golang #315

Closed gedw99 closed 1 year ago

gedw99 commented 1 year ago

Like the design.

Saw there is a rust wasm example.

if you add a golang example compiled with tinygo that would be create

onpaws commented 1 year ago

Thanks for the suggestion! I took a stab at porting the previously made Rust example into Golang/tinygo.

Results

$ ./query_udf.sh
SELECT addi64(1, 2) AS RESULT;
HTTP/1.1 200 OK
content-type: application/json; arrow-schema=%7B%22fields%22%3A%5B%7B%22children%22%3A%5B%5D%2C%22name%22%3A%22result%22%2C%22nullable%22%3Atrue%2C%22type%22%3A%7B%22bitWidth%22%3A64%2C%22isSigned%22%3Atrue%2C%22name%22%3A%22int%22%7D%7D%5D%2C%22metadata%22%3A%7B%7D%7D
x-seafowl-query-time: 426
vary: Authorization, Content-Type, Origin, X-Seafowl-Query
transfer-encoding: chunked
date: Tue, 18 Jul 2023 06:34:14 GMT

{"result":3}

1 + 2 = 3 🎉

NB This was my first time writing Golang and also my first WASM module, sorry for any bugs, which there likely are.

Practical note

Please be aware Seafowl supports registering and invoking UDFs, but doesn't yet support UDF deletion^1, so if you end up iterating on your own WASM module and want to register it in Seafowl >1x, you will probably want to clear the Seafowl database (e.g. rm the seafowl.sqlite file).

In case you're able to share what you build would be curious to check it out :) Hope this is helpful, and good luck!

Deps

onpaws commented 1 year ago

I believe the request has been fulfilled at this point so I'm going to close. If any further assistance is needed, please just ask.

onpaws commented 1 year ago

Closing