Representation of the Coda document as a Go code

Over the past few years I’ve been using Coda as a database and UI for data entry for my standalone application. In the app I used an http library to work with the Coda REST API but I was not satisfied that there was a lot of boring stuff I had to do on top of just making requests via a client library - e.g. creating value objects/DTOs for tables, loading methods per each table etc. Also I’ve been writing in Go and I wanted to have everything strongly-typed and make as much build time checks as possible.

I’ve just completed making a tool that I use in my projects that introspects a Coda document and generates a Go source file comprising structs, constructors, loaders routines, etc per each table.

You can check it on github - https://github.com/artsafin/coda-schema-generator

Sample of the app using generated code - https://github.com/artsafin/coda-schema-generator#example-of-application-using-codaschema

I’m still working on adding more tests for the edge cases and polishing the generated code APIs.

Let me know if you have any ideas or questions! (also if there are go devs would love to get a review)

3 Likes

Very nice! My main comment is that it would be great to have a separate package that simply focuses on providing a Go API for Coda, but I understand that is not your primary goal and having a tight purposeful subset of the API supported inside your package is a good approach. I’ve noticed that Coda provides a swagger/openapi definition so that could be useful for such a package, but I don’t have experience with that.

The code overall looks good to me! Of course there some things that are I would do differently. E.g. I wouldn’t have a const.go file, since that becomes a place to potentially put all sorts of things that have nothing to do with each other together, or raises flags if consts are put in other files, which is a very natural thing to do. Overall it looks thought out and clean.

What a great idea! Thanks so much for sharing it. I’m still quite a novice at Go, so I’ll leave the more targeted feedback to others. Would you mind if we listed this among the client libraries in the API documentation?

There is such package actually - https://github.com/artsafin/coda-go-client. Though it’s used as a dependency of the coda-schema-generator it can be used independently as well.

This client package is generated from the OpenAPI v3 JSON spec using a code generation tool :slight_smile: with a slight patching of the spec beforehand.

The coda-schema-generator is a somewhat step further that creates a more sophisticated “client library” by leveraging the low-level API client library and knowledge about the Coda document.

Thank you!

Yes I would appreciate including it to the client libraries!

@artsafin

this is an extremely impressive body of work indeed.
and you are most generous for sharing it with the community like this.

many thanks indeed.

i see this as not only being useful as it stands, but being extremely useful as an example, framework and starting-point for further work along these lines. i expect to learn much from it.

being able to rapidly (and collaboratively) create a coda document with all the rich features coda provides and then have it rendered as a procedural body of code which is functionally equivalent has a great many uses. i am only starting to think of innovative things that can be achieved with this approach.

i am not familiar with go - but i am able to understand a lot of this code (which is a testament to the clarity of your design and coding). and i look forward to many enjoyable hours exploring this on github.

as darth vader himself said;
impressive,
most impressive!

max

2 Likes

@artsafin - Your library is listed in the docs now! Thanks again for contributing.

1 Like