Skip to content

Instantly share code, notes, and snippets.

@GitHub30
Last active May 1, 2016 09:09
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 GitHub30/8da3aac8090ff731c9bf9a0906584e03 to your computer and use it in GitHub Desktop.
Save GitHub30/8da3aac8090ff731c9bf9a0906584e03 to your computer and use it in GitHub Desktop.
Type for MySQL
var type_for_mysql = function(data) {
if (data === null)
return 'NULL';
var type = typeof data;
if (type === 'boolean')
return 'BOOLEAN';
else if (type === 'number')
return 'INTEGER';
else if (type === 'string')
return `CHAR(${data.length})`;
else if (type === 'object')
return 'JSON';
else
return 'UNKNOWN';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment