Skip to content

Example for simple plpgsql DO statement in db.registerLanguage wiki ? #180

Answered by oguimbal
skilbjo asked this question in Q&A
Discussion options

You must be logged in to vote

Hi !

The pgsql language is not implemented, but it doesnt mean that you cannot execute simple queries (that are supported).

So my answer may be naïve, but did you try something like this ?

db.registerLanguage('plpgsql', ({ code, args, returns }) => {

  assert(code).to.equal(expected); // or whatever

  return () => {
       if (!db.public.one(`select 1 from pg_type where typname = 'transaction_type'`)) {
           db.public.none(`create type transaction_type as enum ('charge', 'refund');`);
        }
    }; 
});

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by skilbjo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #179 on December 24, 2021 10:59.