This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-11
Channels
- # announcements (2)
- # babashka (31)
- # beginners (31)
- # calva (30)
- # cider (23)
- # clerk (1)
- # clojure (46)
- # clojure-austin (5)
- # clojure-brasil (1)
- # clojure-europe (47)
- # clojure-nl (1)
- # clojure-norway (72)
- # clojure-uk (2)
- # clojurescript (39)
- # conjure (1)
- # cursive (16)
- # data-science (1)
- # datomic (35)
- # dev-tooling (4)
- # events (5)
- # introduce-yourself (2)
- # jobs-discuss (5)
- # missionary (3)
- # polylith (11)
- # releases (4)
- # scittle (4)
- # shadow-cljs (18)
- # spacemacs (16)
- # specter (2)
- # squint (27)
- # xtdb (6)
any thoughts on using squint as a language inside PostgreSQL with plv8? details in thread
for example, I got the following code
(doseq [a (range 42 420)
b [10 20 30 40]
:let [ab (* a b)]]
(js/plv8.return_next
{:i ab
:t (str a " * " b " = " ab)}))
to work as a set returning functionI compiled the code with npx squint compile …
+ combined it with core.js (removing any export
references or squint_core.
references from the code… and it worked fine
for optimized usage you may want to bundle the code with:
npx squint --no-run --show -e '(doseq [i (range 10) j (range 10)] [i j])' | npx esbuild --minify --bundle
👍 1
This gives something like:
(()=>{function y(e){if(e==null||e instanceof Function)return e;let t=typeof e;return t==="string"?(n,r)=>p(n,e,r):t==="object"?(n,r)=>p(e,n,r):e}globalThis.toFn=y;var _=1,x=2,a=3,g=4,h=5,m=6;function d(e){return e.constructor===Object}function w(e){if(e!=null){if(d(e))return a;if(e instanceof Map)return _;if(e instanceof Set)return h;if(e instanceof c)return g;if(Array.isArray(e))return x;if(e instanceof o)return m;if(e instanceof Object)return a}}function p(e,t,n=void 0){if(e==null)return n;let r;if(d(e))return r=e[t],r===void 0?n:r;switch(w(e)){case h:e.has(t)&&(r=t);break;case _:r=e.get(t);break;case x:r=e[t];break;default:if(e.get instanceof Function)try{r=e.get(t);break}catch{}r=e[t];break}return r!==void 0?r:n}function A(e){return typeof e=="string"||e===null||e===void 0||e instanceof Object&&Symbol.iterator in e}function s(e){return e==null?[]:A(e)?e:Object.entries(e)}var b=Symbol("Iterable");var v=!1;var o=class{constructor(t){this.gen=t,this.usages=0}[Symbol.iterator](){if(this.usages++,this.usages>=2&&v)try{throw new Error}catch(t){console.warn("Re-use of lazy value",t.stack)}return this.gen()}};o.prototype[b]=!0;function M(e){return new o(e)}function l(e,t,n){return M(function*(){let r=e,u=t,i=n;t===void 0&&(r=0,u=e);let f=r||0;for(i=n||1;u===void 0||f<u;)yield f,f+=i})}var c=class extends Array{constructor(...t){super(),this.push(...t)}};var E=Symbol("meta");console.log("dude");for(let e of s(l(10)))(function(){let t=e;for(let n of s(l(10))){let r=n}return null})();dude;})();
which is a standalone version of the whole thingCREATE FUNCTION set_of_records() RETURNS SETOF rec AS
$$
// plv8.return_next() stores records in an internal tuplestore,
// and return all of them at the end of function.
plv8.return_next( { "i": 1, "t": "a" } );
plv8.return_next( { "i": 2, "t": "b" } );
// You can also return records with an array of JSON.
return [ { "i": 3, "t": "c" }, { "i": 4, "t": "d" } ];
$$
LANGUAGE plv8;
it looks like it wraps the code in an implicit js functionperhaps just define a function and then append the function call at the end of your js blob?
npx squint --show -e '(defn foo [] {:hello true})' | npx esbuild --minify --bundle --format=iife --global-name=my_blob
+ append return my_blob.foo()
👍 1