lib/dataset/sql.js
function (tableAlias) {
            tableAlias = this._toTableName(tableAlias);
            var usedAliases = [], from, join;
            if ((from = this.__opts.from) != null) {
                usedAliases = usedAliases.concat(from.map(function (n) {
                    return this._toTableName(n);
                }, this));
            }
            if ((join = this.__opts.join) != null) {
                usedAliases = usedAliases.concat(join.map(function (join) {
                    if (join.tableAlias) {
                        return this.__toAliasedTableName(join.tableAlias);
                    } else {
                        return this._toTableName(join.table);
                    }
                }, this));
            }
            if (usedAliases.indexOf(tableAlias) !== -1) {
                var base = tableAlias, i = 0;
                do {
                    tableAlias = string.format("%s%d", base, i++);
                } while (usedAliases.indexOf(tableAlias) !== -1);
            }
            return tableAlias;
        }
function (tableAlias) {
            tableAlias = this._toTableName(tableAlias);
            var usedAliases = [], from, join;
            if ((from = this.__opts.from) != null) {
                usedAliases = usedAliases.concat(from.map(function (n) {
                    return this._toTableName(n);
                }, this));
            }
            if ((join = this.__opts.join) != null) {
                usedAliases = usedAliases.concat(join.map(function (join) {
                    if (join.tableAlias) {
                        return this.__toAliasedTableName(join.tableAlias);
                    } else {
                        return this._toTableName(join.table);
                    }
                }, this));
            }
            if (usedAliases.indexOf(tableAlias) !== -1) {
                var base = tableAlias, i = 0;
                do {
                    tableAlias = string.format("%s%d", base, i++);
                } while (usedAliases.indexOf(tableAlias) !== -1);
            }
            return tableAlias;
        }
function ( tableAlias ) { tableAlias = this . _toTableName ( tableAlias ) ; var usedAliases = [ ] , from , join ; if ( ( from = this . __opts . from ) != null ) { usedAliases = usedAliases . concat ( from . map ( function ( n ) { return this . _toTableName ( n ) ; } , this ) ) ; } if ( ( join = this . __opts . join ) != null ) { usedAliases = usedAliases . concat ( join . map ( function ( join ) { if ( join . tableAlias ) { return this . __toAliasedTableName ( join . tableAlias ) ; } else { return this . _toTableName ( join . table ) ; } } , this ) ) ; } if ( usedAliases . indexOf ( tableAlias ) !== - 1 ) { var base = tableAlias , i = 0 ; do { tableAlias = string . format ( "%s%d" , base , i ++ ) ; } while ( usedAliases . indexOf ( tableAlias ) !== - 1 ) ; } return tableAlias ; }
Creates a unique table alias that hasn't already been used in this dataset.

@example

DB.from("table").unusedTableAlias("t");
//=> "t"

DB.from("table").unusedTableAlias("table");
//=> "table0"

DB.from("table", "table0"]).unusedTableAlias("table");
//=> "table1"

@param {String|patio.sql.Identifier} tableAlias the table to get an unused alias for.

@return {String} the implicit alias that is in tableAlias with a possible "N"
if the alias has already been used, where N is an integer starting at 0.
Creates a unique table alias that hasn t already been used in this dataset .