Skip to content

Well this is awesome... #19

Description

@fullmetal-fred

Hey there @burggraf, nice job!
I'm wondering if there's any progress getting this added as an official extension or maybe on dbdev as a pglet?

I was wanting to use JSONata within postgres functions directly...thanks to this I can!

create or replace function evaluate_jsonata(
    in jsonata_expression text,
    in json_data jsonb,
    out result jsonb,
    out error text
)
returns SETOF record as $$
    
    try {
        const jsonata = require('https://cdn.jsdelivr.net/npm/jsonata@1.8.6/jsonata.min.js');
        const expression = jsonata(jsonata_expression);
        const result = expression.evaluate(json_data);
        return {
            result: result,
            error: null
    };
    } catch (e) {
        return {
            result: null,
            error: e.message
        };
    }

$$ language plv8;

select result from test_jsonata('$sum(*)','{"a":1,"b":2}')
returns 3 🤘🏻

So cool!!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions