Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bin/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(/^\//)
Expand All @@ -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';
Expand Down
7 changes: 5 additions & 2 deletions lib/guess-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down