Last active
May 1, 2016 09:09
-
-
Save GitHub30/8da3aac8090ff731c9bf9a0906584e03 to your computer and use it in GitHub Desktop.
Type for MySQL
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
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