github gnormal/gnorm v0.2
Gnorm v0.2

latest releases: v1.1.1, v1.1.0, v1.0.0...
6 years ago

A lot of rework has been done under the covers, with a few new features and new data layout.

Command Changes

New: gnorm init

gnorm init produces a default gnorm.toml file and template files to help you get started with gnorm.

Configuration Changes

Removed: TemplateDir

Because of the change to support multiple output file/content template pairs, a dedicated value of where templates live isn't necessary, you can specify the relative path for each content template directly.

Changed: SchemaPath, TablePath, EnumPath -> SchemaPaths, TablePaths, EnumPaths

You may now specify any number of output targets for each content template type. TablePath, EnumPath, and SchemaPath are now toml tables called SchemaPaths, TablePaths, EnumPaths, allowing you to specify multiple output target / content template pairs for each.

For example (note the s on the end of the name in brackets):

[TablePaths]
"{{.Schema}}/tables/{{.Table}}/{{.Table}}.go" = "tableORM.tmpl"
"public/{{.Schema}}/tables/{{.Table}}.html" = "tableHTML.tmpl"

Migration

To translate an old style single value `TablePath = "some/filepath/template", use the template string on the left, as above, and "table.gotmpl" as the template name on the right. (enums expect "enum.gotmpl" and schemas "schema.gotmpl"). And don't forget to include the TemplateDir if you used one before.

Notes

Because these are toml tables, they need to be at the end of the configuration with the rest of the tables. There can't be any standalone values after them.

Gnorm doesn't care what the extension of the file is for the template, so use whatever you like.

New: Params

There is now a [Params] table in the config which can hold whatever data you want. This data will be accessible to templates via the .Params data value for every content type.

For example:

[Params]
showHidden = true
myName = "Bob"

Data Changes

New artisanal, hand written docs about data! https://gnorm.org/templates/data/

Data has changed a lot... but with minimum impact on existing templates. The data layout for Tables, Schema, and Enums has had a bunch of things added at the top level. Every template now receives all the data about the DB in a .DB value. It also receives much of the data from the config file in a .Config value. Finally, the Params from the config file are available in .Params. The previous top-level data for Tables, Schema, and Enums are now available in .Table, .Schema, and .Enum respectively.

See https://gnorm.org/templates/data/ for more information

MIgration

To use your existing template, it's just a matter of putting {{with .Table}} (or .Enum or .Schema as appropriate) at the top of your content template and {{end}} at the end of the template, and then the values will be the same as before, with two exceptions: in tables and enums, the .Schema value is now a reference to the actual schema object. to get its name or DBname, substitute .Schema.Name for the old template's .Schema, and .Schema.DBName for the old template's .DBSchema.

Don't miss a new gnorm release

NewReleases is sending notifications on new releases.