volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Export variables to JSON #303

Closed saulortega closed 6 years ago

saulortega commented 6 years ago

Hi @aarondl

What do you think about to export, during the models generation, a file that contains a JSON string with all variables that SQLBoiler uses to create the models?

Such as this:

{
    "models": [
        {
            "Table": {
                "Name": "pilots",
                "Columns": [
                    //...
                ],
            },
            "DownSingular": "pilot",
            "UpSingular": "Pilot",
            //...
        }
    ]
}

This to facilitate a third-party implementation: A third party tool reads that file, get the variables, and write its own custom implementations that extends SQLBoiler.

That would facilitate my https://github.com/saulortega/restsqlboiler, for example. :)

Maybe it's enough with marshaling boilingcore.State

aarondl commented 6 years ago

Hey Saul. Take a look at the v3 --debug output. It outputs the db info, templates, and calculated aliases. I think that's probably sufficient. Let me know.

aarondl commented 6 years ago

Also in these particular cases it's probably easier to copy the sqlboiler templates to a new dir, add your own to that dir, and then use --basedir to point to those templates. That way you have full control over generation and can supply new templates like you have there too. Not sure if that's helpful for you, just something I thought of. Seems easier than writing a new tool that duplicates a lot of the templatization that sqlboiler does already.

saulortega commented 6 years ago

Oh, that sounds good. I'll try.

saulortega commented 6 years ago

Okay, that is the best way to do it. I had not thought of that.