Last active
November 2, 2018 12:48
-
-
Save kristianheljas/bd55ae41690090929a0a6ebf30eacf14 to your computer and use it in GitHub Desktop.
Create formatted PhpDoc @Property declarations from mysql table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @database = "<database>", @table = "<table>"; | |
SET @maxTabs = (SELECT CEIL(MAX(LENGTH(`column_name`)) / 4) + 1 | |
FROM information_schema.`COLUMNS` | |
WHERE `TABLE_SCHEMA` = @database AND `TABLE_NAME` = @table); | |
SELECT CONCAT(' * @property ', CASE | |
WHEN data_type IN ('char', 'varchar', 'tinytext', 'text', 'mediumtext', 'longtext', 'binary', 'varbinary', 'tinyblob', 'blob', 'mediumblob', 'json', 'enum', 'set') THEN 'string\t' | |
WHEN column_type = 'tinyint(1)' THEN 'bool\t' | |
WHEN data_type IN ('tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint', 'year') THEN 'int\t' | |
WHEN data_type IN ('decimal', 'dec', 'numeric', 'fixed', 'float', 'double', 'real') THEN 'float\t' | |
WHEN data_type IN ('date', 'datetime', 'timestamp', 'time', '') THEN 'Carbon\t' | |
ELSE 'mixed\t' | |
END, '$', `column_name`, REPEAT('\t', @maxTabs - FLOOR((LENGTH(column_name) + 1) / 4)), column_type) | |
FROM information_schema.`COLUMNS` | |
WHERE `TABLE_SCHEMA` = @database AND `TABLE_NAME` = @table; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace
<database>
and<table>
variables to the table you want to export