Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax highlighting doesn't work when storing mustache files in function definitions #18

Open
steve-chavez opened this issue Jan 26, 2024 · 3 comments
Labels

Comments

@steve-chavez
Copy link
Member

steve-chavez commented Jan 26, 2024

Problem

As it can be seen on https://github.com/PostgREST/plmustache?tab=readme-ov-file#sections, regular syntax highlighting for mustache files doesn't work.

Solution

Add a psql command that can obtain the function body from another file.

\create_function from ./templates/hello.mustache hello(arg text) returns int LANGUAGE plmustache

I've submitted this on https://www.postgresql.org/message-id/CAGRrpzZnoWY-kK_0qK-OY%3D-e0eDqhc5kdFSkuxN0mxe9iuiz0Q%40mail.gmail.com

It can also be tried on this branch https://github.com/steve-chavez/postgresql/tree/cf with:

$ nix-shell
$ pg-build && with-pg psql

\create_function from ./src/pl/plpython/data/max.py public.max(a int, b int) returns int language plpython3u

select max(3, 4);

Alternatives

  • A special syntax highlighter for postgres functions with different langs in VIM? This would have to be done for various editors/IDEs though.
  • Another executable besides psql that deploys the functions based on mustache files.
@steve-chavez
Copy link
Member Author

Really nice that this already sparked some discussion! Looks like the final interface will be like this though:

\file_read fbody source_file.txt
CREATE FUNCTION foo() RETURNS whatever AS :'fbody' LANGUAGE ...;

@wolfgangwalther You mentioned you follow the mailing list daily. I was wondering, what's the protocol on implementing a feature? Should I just jump in with a new patch? Not sure if I should leave that to Tom Lane since he proposed it.

@wolfgangwalther
Copy link
Member

You mentioned you follow the mailing list daily. I was wondering, what's the protocol on implementing a feature? Should I just jump in with a new patch? Not sure if I should leave that to Tom Lane since he proposed it.

I don't expect him to work on this. If so, he would likely have said that.

I guess you could just write a patch for the above, yes.

@steve-chavez
Copy link
Member Author

Note that this already works as:

\set tpl `cat tpl.mustache`
create function tpl() returns text as :'tpl' language plmustache;

On the pg patch we're working on a native way that's not dependent on the shell.

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

No branches or pull requests

2 participants