I’m working on a framework in PHP, part of this frameworks job is to write SQL code to generate new MySQL columns.
What is the most elegant way to pass in a bunch of parameters for a column and then turn that into SQL code? As an example here is some YAML I have, that specifies parameters for creating a varchar column:
- type: character data-type: type: varchar length: 255 decimals: null unsigned: null zerofill: null collate: utf8_unicode_ci character-set: utf8 binary: false spatial-type: null values: null nullify: true default: null increment: false unique: false primary: false comment: This is a small general text field. format: default storage: default
My design constraints are as follows:
- The YAML cannot contain any SQL syntax
- The PHP code must be as concise as possible.
I recommend you make a class Column that takes, as a constructor argument, an array that can define the various configuration points you want. The ones that don’t matter in each particular case you just don’t define.