Templates for tables creation


Staff member
There are tables, having a similar structure, that I have to create quite often.
For example in my apps I typically have a lot of lookup tables (what we call linked tables in DaDaBIK) having only two fields (id and name), e.g. table states having fields:

ID_state (INT, PK, autoincrement) name_state (varchar 255)

Having templates, defined in config_custom.php, for such tables would allow to create a table in one click, after having defined the name and selected the template to use.

Something like:

$table_templates[0]['name'] = 'lookup_table';
$table_templates[0]['fields'][0]['name'] = 'ID';
$table_templates[0]['fields'][0]['type' = 'int;
.... other info about the field here, e.g. PK constraint ... 
$table_templates[0]['fields'][1] = 'name';
$table_templates[0]['fields'][1]['type' = 'varchar(355);

A custom PHP function could also be set to define transformations of the field name using the table name as well, setting rules that allow, for example, starting from "ID" to get "ID_state".

There are also tables that you probably use, with slightly variations, in many projects, e.g. a customers table or a products table.
You could paste in your config_custom, for any new project, the library of templates for table you often use, to create such tables in a click.

A library of templates with a suggested schema for the most common tables could be also included in DaDaBIK.
Upvote 0