1. 12
  1.  

  2. 5

    This looks interesting (and has some parallels with PostgREST), although I’m curious why you chose to template Go code with .NET instead of writing in one or the other?

    1. 6

      This does code generation whereas I think PostgREST does it all in memory. Moreover this gives you an entire application you have full control over if you want. Whereas you kind of have to treat PostgREST as its own black box.

      Additionally, this supports Go today but should be easier to extend to other languages because it’s based on text templates. I started with Go because I’m most familiar with its ecosystem for web development and I can build something quickly that’s still reasonably production-ready.

      I’d like to extend support to other databases over time as well.

      I went with F# because I wanted a high-level statically typed language with a mature ecosystem for database interactions and text manipulation. For example, the error messages in the template library (Scriban) are excellent, giving you the exact line number of a misconfigured template.

      Go would be much harder to do this sort of thing without reverting to a lot of unsafe dynamism with reflection or empty interfaces. Possible, but not as easy.

    2. 1

      The “limit” parameter needs a default and sensible upper value so users can’t just dump the tables. Presumably more complex queries requiring joins, group by, etc would be implemented as views, given the limited filter syntax? I don’t really care to install dot net as dependency to generate some go code, that if I edited, my edits would be wiped out the next time I regenerated the project.

      1. 1

        The “limit” parameter needs a default and sensible upper value so users can’t just dump the tables.

        Yep, good idea. Easy enough to do.

        Presumably more complex queries requiring joins, group by, etc would be implemented as views, given the limited filter syntax?

        That is such an obvious idea and I had never thought of doing this. I built up some really complicated column/json-field mappings in the past because I wasn’t thinking of views. Thank you!

        I don’t really care to install dot net as dependency to generate some go code

        I haven’t spent much time on packaging of the CLI yet but I imagine it will be a binary or Docker image you can use.

        that if I edited, my edits would be wiped out the next time I regenerated the project.

        You could use this project in two ways: 1) generated boilerplate that you use once and edit directly or 2) templates that you extend as needed. The two things I’m looking into are template file overrides and also hooks for you to add non-generated code alongside generated code.

      2. 1

        I wonder if any of the Rust web frameworks have support for auto-generating (or scaffolding, to use the Rails term) a REST API with this level of features.

        1. 1

          The dbcore code is broken out by templates per language/framework/whatever already so I’d love to see submissions for Rust (or any language, Java is in my list) meeting this API spec.