Saturday, March 11, 2023
HomeGolangA device to transform Go struct right into a SQL table -...

A device to transform Go struct right into a SQL table – Launches


Hey people, I composed a device that transforms Go structs right into SQL question that’ll develop a table with the struct’s areas. This is the initial variation, I do intend on boosting it in the future. It is created in 100% Javascript as it is perfect for the job.

P.s: I composed this after looking Google for a device similar to this and also it functions finest with postgresql

You can discover it right here: https://cheikhshift.github.io/struct-to-sql/

Resource code right here: https://github.com/cheikhshift/struct-to-sql




1 Like

Taking Into Consideration that we get on the “ Golang Bridge” discussion forum website, I might be prejudiced, yet I would certainly say that Javascript is rarely suitable for the job :laughing:

Anyhow, this is a wonderful proof-of-concept. I would certainly advise:

  1. Make use of a real Go phrase structure parser:

    Your code thinks that the Go struct name gets on one line and also each area gets on each succeeding line till you reach the last closing } If your input Go code has a phrase structure mistake, or is not formatted with the existing gofmt application, it will certainly not create the proper outcome. As an example:

     kind Struct1 struct {
    kind Struct2 struct {
    S string.
    I int.
    }
    
  2. The code does not produce one of the most optimum kinds for PostgreSQL. As an example, a solitary byte in the struct need to not end up being a VARCHAR in PostgreSQL. It needs to be char( 1 ) or bytea

  3. Include assistance for data sources besides PostgreSQL, such as MySQL, SQLite3, Microsoft SQL Web server, and so on

  4. Include assistance for various calling conventions. Not everybody utilizes “snake-case” and also some individuals could be thinking about utilizing this code to produce SQL questions versus pre-existing 3rd-party data sources.


Please Note

I take place to be working with my very own SQL-generator from Go struct meanings, so I am, probably, a little bit “fussy” regarding this!



3 Sort

If you wished to make use of a Go phrase structure parser, you might potentially make use of WASM:

I such as the concept of never ever sending out any type of information back to the web server. Matt Holt’s outstanding crinkle to go and also json to go do not send out anything back to the web server and also therefore I can utilize them without personal privacy worries. So, maintaining this running 100% in the web browser is, in my viewpoint, suitable.

Anyhow, wonderful beginning. This is the amount of effective open resource jobs have actually begun: by someone developing a remedy to a trouble they have. Maintain the great!



1 Like

This subject was immediately shut 90 days after the last reply. New replies are no more permitted.

RELATED ARTICLES

Most Popular

Recent Comments