Skip to content

Instantly share code, notes, and snippets.

@bklein01
Created July 21, 2016 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bklein01/dd18277a76ab0bf5629362c36b4f5962 to your computer and use it in GitHub Desktop.
Save bklein01/dd18277a76ab0bf5629362c36b4f5962 to your computer and use it in GitHub Desktop.
Quick SQL to help build TypeScript Model Classes For a Database/Restful API
SELECT CONCAT(column_name, ': ', (CASE data_type WHEN 'bigint' THEN 'number' WHEN 'smallint' THEN 'number' WHEN 'char' THEN 'string' WHEN 'tinyint' THEN 'number' WHEN 'int' THEN 'number' WHEN 'varchar' THEN 'string' WHEN 'text' THEN 'string' WHEN 'timestamp' THEN 'string' WHEN 'date' THEN 'string' WHEN 'datetime' THEN 'string' WHEN 'decimal' THEN 'number' END), ';')
FROM information_schema.columns
WHERE table_name = '{tablename}' AND table_schema = '{database}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment