Created
June 7, 2022 22:35
-
-
Save RobKohr/75eb5b26f8565faf4ed3755fe1976c0a to your computer and use it in GitHub Desktop.
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
let out = 'create table some_table_name ('; | |
const fields = Object.keys(row); | |
for (var i = 0; i < fields.length; i++) { | |
const value = row[fields[i]]; | |
const originalType = typeof value; | |
let fieldType = 'unknown $originalType'; | |
switch (originalType) { | |
case 'string': | |
fieldType = 'varchar(255)'; | |
break; | |
case 'number': | |
if (Math.round(value) === value) { | |
fieldType = 'integer'; | |
} else { | |
fieldType = 'real'; | |
} | |
break; | |
case 'object': | |
fieldType = 'varchar(255)'; | |
break; | |
case 'boolean': | |
fieldType = 'boolean'; | |
break; | |
} | |
out += `\n${fields[i]} ${fieldType}, `; | |
} | |
out += '); ' | |
console.log(out); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment