davrontb / postgresql-to-knex

PostgreSQL to Knex.js converter
17 stars 1 forks source link

Error with triggers and functions #1

Open esvanegas opened 2 years ago

esvanegas commented 2 years ago

When trying to create a trigger or a function, to_knex function returns CreateFunctionStmt is not implemented message I understand knex doesn't allow to create triggers and functions due it's limited to PostgreSQL only. But maybe to_knex function could return a .raw knex object.

Steps to reproduce the issue:

const to_knex = require('postgresql-to-knex');

console.log(to_knex(`
        CREATE OR REPLACE FUNCTION public.exampleFunction()
            RETURNS trigger
            LANGUAGE plpgsql
        AS $function$
        DECLARE
            results record;
        BEGIN
            SELECT *  INTO results FROM example
            PERFORM pg_notify('event',row_to_json(results)::text);
            RETURN NULL;
        END;
        $function$
`))
davrontb commented 2 years ago

postgresql-to-knex uses pg-query-parser package which uses uses the real PostgreSQL parser(libpg_query package). CreateFunctionStmt is not implemented error comes from that package which parses the query before converting it to knexJs.

Thank you for your suggestion about .raw function. I will try to implement it.