GithubHelp home page GithubHelp logo

Comments (3)

oguimbal avatar oguimbal commented on May 22, 2024 1

CREATE FUNCTION statements are now partially supported in [email protected], via the registration of custom languages.

This allows to provide either a custom compiler (for custom scripts such as javascript via eval()), or a mock implementation for each function creation.

(I dont think actual plpgsql support is coming anytime soon)

from pg-mem.

RodolfoSilva avatar RodolfoSilva commented on May 22, 2024

Supporting the "create function" statement, without actually parsing/compiling the function body (which would force you to declare mocks for your created pg functions directly in JS).

Hey @oguimbal what's the path that you suggest to implement this? I think this is most easy way to do this right now. Allowing the stub implementation of PSQL functions like extensions.

from pg-mem.

oguimbal avatar oguimbal commented on May 22, 2024

The path... you mean how it must be implemented ?

I've been wanting to add that in contributing.md for a while, so i'll do that now.

Like any feature of pg-mem, it breaks down into:

A) Implement its parser

NB: For this use case (create function stubs), this will not exactly look like below, because create function body must be "ignored" ... thus, I think that the lexer must be modified. Which is a bit tricky. But otherwise, it goes like that:

  1. Look very hard at the statement syntax
  2. Add the target statement type in pgsql-ast-parser AST based on what I understood.
  3. Implement unit tests I want to pass (ex with create sequence UTs)
  4. Implement its syntax in a new nearley file (example with the create sequence statement) and reference it in main.ne
  5. Work on it until unit tests are all failing, but with an error which is not a parsing error
  6. Add an entry for the new statement in IAstPartialMapper here and add its default visitor implem like here and here until compiler stops screaming
  7. Add the "toSql" implementation of the new statement like here (until compiler stops)
  8. Check that ALL unit tests are green (not only the new ones)
  9. Release pgsql-ast-parser

B) Executor

  1. install pgsql-ast-parser@latest
  2. Write unit tests (create sequence UTs are here, for instance)
  3. Implement statement... that's the less codified thing, but it starts by adding a new case in this switch for new statements (which should fail to compile with the newly installed pgsql-ast-parser), or fix compilation errors & unit tests for other amendments to the parser.
  4. Check that ALL unit tests are OK
  5. Release 🎉

I'll do that soon, when I find a bit of time 😃

from pg-mem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.