Template Data
The data passed to the templates is defined below.
Schema Data
Data passed to each schema template:
Property |
Type |
Description |
Schema |
Schema |
The schema being rendered |
DB |
DB |
The data for the whole DB |
Config |
Config |
Gnorm config values from the gnorm.toml file |
Params |
map[string]anything |
the values from the Params entry in the config file |
Table Data
Data passed to each table template:
Property |
Type |
Description |
Table |
Table |
the table being rendered |
DB |
DB |
The data for the whole DB |
Config |
Config |
Gnorm config values from the gnorm.toml file |
Params |
map[string]anything |
the values from the Params entry in the config file |
Enum Data
Data passed to each enum template:
Property |
Type |
Description |
Enum |
Enum |
the enum being rendered |
DB |
DB |
The data for the whole DB |
Config |
Config |
Gnorm config values from the gnorm.toml file |
Params |
map[string]anything |
the values from the Params entry in the config file |
Type Definitions
These are the definitions of all the complex types referenced by the above.
DB
Data representing the entire DB schema(s).
Property |
Type |
Description |
Schemas |
list of Schemas |
all the schemas parsed by gnorm |
SchemasByName |
map[string]Schema |
map of schema DBName to Schema |
Column
Column is the data about a DB column of a table.
Property |
Type |
Description |
Table |
Table |
the table this column is in |
Name |
string |
the converted name of the column |
DBName |
string |
the original name of the column in the DB |
Type |
string |
the converted name of the type |
DBType |
string |
the original type name of the column in the DB |
IsArray |
boolean |
true if the column type is an array |
Length |
integer |
non-zero if the type has a length (e.g. varchar[16]) |
UserDefined |
boolean |
true if the type is user-defined |
Nullable |
boolean |
true if the column is not NON NULL |
HasDefault |
boolean |
true if the column has a default |
Comment |
string |
the comment attached to the column |
IsPrimaryKey |
boolean |
true if the column is a primary key |
Ordinal |
int64 |
the column’s ordinal position |
IsFK |
boolean |
true if the column is a foreign key |
HasFKRef |
boolean |
true if the column is referenced by a foreign key |
FKColumn |
ForeignKeyColumn |
foreign key column definition |
FKColumnRefs |
ForeignKeyColumns |
all foreign key columns referencing this column |
FKColumnRefsByName |
map[string]ForeignKeyColumn |
all foreign key columns referencing this column by foreign key name |
Orig |
db-specific |
the raw database column data (different per db type) |
Columns
Columns is an ordered list of Column values from a table. Columns
have the following properties:
Property |
Type |
Description |
DBNames |
Strings |
the ordered list of DBNames of all the columns |
Names |
Strings |
the ordered list of Names of all the columns |
ByOrdinal |
Columns |
the columns in ordinal order |
ConfigData
Property |
Type |
Description |
ConnStr |
string |
the connection string for the database |
DBType |
string |
the type of db |
Schemas |
list of string |
the schema names to generate files for |
IncludeTables |
map[string] list of string |
whitelist map of schema names to table names in that schema to generate files for. |
ExcludeTables |
map[string] list of string |
blacklist map of schema names to table names in that schema to not generate files for. |
PostRun |
list of string |
the command to run on files after generation |
TypeMap |
map[string]string |
map of DBNames to converted names for column types |
NullableTypeMap |
map[string]string |
map of DBNames to converted names for column types (used when Nullable=true) |
PluginDirs |
list of string |
ordered list of directories to look in for plugins |
OutputDir |
string |
the directory where gnorm should output all its data |
StaticDir |
string |
the directory from which to statically copy files to outputdir |
Enum
An enum is a user-defined column type that has a set of allowable values.
Property |
Type |
Description |
Name |
string |
the converted name of the enum |
DBName |
string |
the original name of the enum in the DB |
Schema |
Schema |
the schema the enum is in |
Table |
Table |
(mysql only) the table this enum is part of |
Values |
list of EnumValue |
the list of possible values for this enum |
Enums
Enums is a list of Enum values from a schem. Enums
have the following properties:
Property |
Type |
Description |
DBNames |
Strings |
the ordered list of DBNames of all the enums |
Names |
Strings |
the ordered list of Names of all the enums |
EnumValue
Property |
Type |
Description |
Name |
string |
the converted label of the enum |
DBName |
string |
the original label of the enum in the DB |
Value |
int |
the value for this enum value (order) |
ForeignKey
Property |
Type |
Description |
DBName |
string |
the original name of the foreign key constraint in the db |
Name |
string |
the converted name of the foreign key constraint |
TableDBName |
string |
the original name of the table in the db |
RefTableDBName |
string |
the original name of the foreign table in the db |
Table |
Table |
the foreign key table |
RefTable |
Table |
the foreign key foreign table |
FKColumns |
ForeignKeyColumns |
all foreign key columns belonging to the foreign key |
ForeignKeys
ForeignKeys is a list of ForeignKey objects. The list has the following methods on it:
Property |
Type |
Description |
DBNames |
Strings |
the list of DBNames of all the foreign keys |
Names |
Strings |
the list of converted names of all the foreign keys |
ForeignKeyColumn
ForeignKeyColumn represents a column in the current table that references the value of a column in another table.
Property |
Type |
Description |
DBName |
string |
the original name of the foreign key constraint in the db |
ColumnDBName |
string |
the original name of the column in the db |
RefColumnDBName |
string |
the original name of the foreign column in the db |
Column |
Column |
the foreign key column |
RefColumn |
Column |
the referenced column |
ForeignKeyColumns
ForeignKeyColumns is a list of ForeignKeyColumn objects. The list has the following methods:
Property |
Type |
Description |
DBNames |
Strings |
the list of DBNames of all the foreign keys |
ColumnDBNames |
Strings |
the list of column database names |
RefColumnDBNames |
Strings |
the list of foreign column database names |
Schema
A schema represents a namespace of tables and enums in a database.
Property |
Type |
Description |
Name |
string |
the converted name of the schema |
DBName |
string |
the original name of the schema in the DB |
Tables |
Tables |
the list of Table values in this schema |
Enums |
Enums |
the list of Enum values in this schema |
TablesByName |
map[string]Table |
map of DBName to Table. |
Strings
Strings is a list of string values with the following methods (not avaialable with external template engines)
Method |
Arguments |
Description |
Except |
vals ([]string) |
Except returns a Strings value with the given values removed from the list (if they existed). The check is case sensitive. |
Sorted |
vals () |
Sorted returns a sorted Strings value. |
Sprintf |
format (string) |
Sprintf calls fmt.Sprintf(format, str) for every string in this value and returns the results as a new Strings value. |
Table
Property |
Type |
Description |
Name |
string |
the converted name of the table |
DBName |
string |
the original name of the table in the DB |
Type |
string |
the type of table (usually VIEW or TABLE BASE) |
Comment |
string |
the comment attached to the table |
IsView |
bool |
true if the table is actually a view |
IsInsertable |
bool |
true if the table accepts inserts (postgres only) |
Schema |
Schema |
the schema this table is in |
Columns |
Columns |
ordered list of Database columns |
ColumnsByName |
map[string]Column |
map of column dbname to column |
PrimaryKeys |
Columns |
primary key columns |
HasPrimaryKey |
bool |
does the column have at least one primary key |
Indexes |
Indexes |
the list of indexes on the table |
IndexesByName |
map[string]Index |
map index dbname to index |
ForeignKeys |
ForeignKeys |
list of foreign keys |
ForeignKeyRefs |
ForeignKeys |
foreign keys referencing this table |
FKByName |
map[string]ForeignKey |
foreign keys by foreign key name |
FKRefsByName |
map[string]ForeignKey |
foreign keys referencing this table by name |
Tables
Tables is list of Table values from a schema. Tables
have the following properties:
Property |
Type |
Description |
DBNames |
Strings |
the list of DBNames of all the tables |
Names |
Strings |
the list of Names of all the tables |
Index
Property |
Type |
Description |
Name |
string |
the converted name of the index |
DBName |
string |
the name of the index from the database |
IsUnique |
bool |
true if the index is unique |
Columns |
Columns |
the list of the columns used in the index |
Indexes
Indexes is a list of Index values for a table.
Property |
Type |
Description |
Names |
Strings |
the list of Names of the indexes |
DBNames |
Strings |
the list of DBNames of the Indexes |