lessql
lessql copied to clipboard
Add discovery
@rubenvincenten suggested adding auto-discovery of keys for engines like InnoDB that support meta-information.
Just wrote this little snippet: https://gist.github.com/rubenvincenten/78963552b6da0045b5e4bd99d243ceb0#file-convention-php
If a ConventionAdapterInterface with getPrimaryKey, getReferencingColumn and getBackReferencingColumn could be added that'd be great :)
In __construct you'd add a second parameter typehinted by that interface. If that parameter would be null, you could make the $convention_adapter use a default lessql convention. The functions in lessql\database would then consult $this->convention_adapter instead of using properties that can be modified by setter methods.
This would also add options like support for chain of responsibility adapters.
API-wise, I believe discovery should be more like $db->discover( $options ) which would figure out the columns and set them using the existing API. This way you can combine discovery and custom settings, plus there's no need for another interface. PRs welcome!