Skip to content

Instantly share code, notes, and snippets.

@poga
Created March 3, 2014 16:30
Show Gist options
  • Save poga/9328711 to your computer and use it in GitHub Desktop.
Save poga/9328711 to your computer and use it in GitHub Desktop.
export function mount-storage (plx, schema, table, cb)
# import a package
next <- plx.import-bundle-funcs 'jsonpatch', require.resolve("jsonpatch/package.json")
<- next!
<- plx.mk-user-func 'plv8x.json apply_patch(json, json[])', 'jsonpatch:apply_patch'
# import a module (without package.json)
next <- plx.import-bundle-funcs 'pgrest_schemaless', require.resolve('./user_func')
<- next!
# ...
storage <- mount-storage plx, SCHEMA, TABLE
err, {row}? <- plx.conn.query "select pgrest_schemaless_set($1) as ret" [{}]
throw err if err
# Uncaught Error: TypeError: Cannot read property 'pgrest_schemaless_set' of undefined
# at Connection.<anonymous> (/Users/poga/MyProject/pgrest/pgrest-schemaless/node_modules/pgrest/node_modules/plv8x/node_modules/pg/lib/native/index.js:202:17)
# at Connection.EventEmitter.emit (events.js:95:17)
export function pgrest_schemaless_set (params)
query = "select apply_patch('{}'::json, ARRAY['{\"op\": \"add\", \"path\": \"/new\", \"value\": \"new\"}'::json]) as ret;"
console.log query
return plv8.execute query
pgrest_schemaless_set.$plv8x = '(plv8x.json):plv8x.json'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment