'use strict';

function stripTableName(name) {
    return name.split('.').pop();
}

// This class is used to help generate the names of node query columns
module.exports = class ColumnNamer {
    constructor (columns) {
        this.columns = columns.map(name => stripTableName(name));
    }

    uniqueName(baseName) {
        var name = baseName;
        var ok = this.isUnique(name);
        if (!ok) {
            // try adding a numeric suffix
            var count = 1;
            while (!ok) {
                name = baseName + '_' + (++count);
                ok = this.isUnique(name);
            }
        }
        this.columns.push(name); // ?
        return name;
    }

    isUnique(name) {
        // TODO: should this be case-insensitive?
        return !this.columns.includes(name);
    }

};

'use strict';

function stripTableName(name) {
    return name.split('.').pop();
}

// This class is used to help generate the names of node query columns
module.exports = class ColumnNamer {
    constructor (columns) {
        this.columns = columns.map(name => stripTableName(name).toLowerCase());
    }

    uniqueName(baseName) {
        baseName = baseName.toLowerCase();
        var name = baseName;
        var ok = this.isUnique(name);
        if (!ok) {
            // try adding a numeric suffix
            var count = 1;
            while (!ok) {
                name = baseName + '_' + (++count);
                ok = this.isUnique(name);
            }
        }
        this.columns.push(name);
        return name;
    }

    isUnique(name) {
        return !this.columns.includes(name);
    }

};

Make column names case-insensitively unique
Make column names case-insensitively unique

Force added column names to be lowercase, actually
