diff --git a/bin/tables.js b/bin/tables.js index 44377e5..2f74886 100755 --- a/bin/tables.js +++ b/bin/tables.js @@ -69,6 +69,11 @@ command.option( expression that starts with "/", for example "/^(key|column)$" or can be a comma-delimited list of columns such as "key|column_1" or ".*key|.*id".` ); +command.option( + '-s, --string-columns [name]', + `A comma-delimited list of columns that would be treated as string instead of guessed. + Only the length of the string would be guessed.` +); command.option( '-t, --transformer [file]', `Reference to JS file that exports a function to transform data @@ -150,6 +155,9 @@ async function cli() { key: command.key ? _.map(command.key.split(','), d => _.snakeCase(d.trim())) : undefined, + stringColumns: command.stringColumns + ? _.map(command.stringColumns.split(','), d => _.snakeCase(d.trim())) + : undefined, id: command.id ? command.id : undefined, fieldsToIndex: command.indexFields && command.indexFields.match(/^\//) @@ -170,7 +178,7 @@ async function cli() { transformer: command.transformer ? command.transformer : undefined, models: command.models ? command.models : undefined }; - + // Input type specific options if (command.jsonPath) { options.format = 'json'; diff --git a/lib/guess-model.js b/lib/guess-model.js index 923e0af..421d38e 100644 --- a/lib/guess-model.js +++ b/lib/guess-model.js @@ -129,9 +129,12 @@ function dataToType(data, name, tablesOptions = {}) { let maxLength = _.maxBy(data, d => (d && d.length ? d.length : 0)); maxLength = maxLength ? maxLength.length : maxLength; let kind; - + // If string is passed as option we just use that + if (tablesOptions.stringColumns && tablesOptions.stringColumns.indexOf(_.snakeCase(name)) != -1) { + kind = 'STRING'; + } // If none, then just assume string - if (_.size(data) === 0) { + else if (_.size(data) === 0) { return Sequelize.STRING; } // If there is only one kind, stick with that