Reputation: 5992
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:
Upvotes: 1
Views: 259
Reputation: 1340
Not totaly related but do you know the Propel project ?
They use xml to explain model but the symfony project (which use propel as a plugin) use yaml.
Upvotes: 0
Reputation: 124325
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.
Upvotes: 1