typeorm#DefaultNamingStrategy TypeScript Examples

The following examples show how to use typeorm#DefaultNamingStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: namingStrategy.ts    From squid with GNU General Public License v3.0 6 votes vote down vote up
export class SnakeNamingStrategy extends DefaultNamingStrategy {
    tableName(className: string, customName?: string): string {
        return customName || toSnakeCase(className)
    }

    columnName(
        propertyName: string,
        customName?: string,
        embeddedPrefixes: string[] = []
    ): string {
        return (
            toSnakeCase(embeddedPrefixes.join('_')) +
            (customName || toSnakeCase(propertyName))
        )
    }

    relationName(propertyName: string): string {
        return toSnakeCase(propertyName)
    }

    joinColumnName(relationName: string, referencedColumnName: string): string {
        return toSnakeCase(`${relationName}_${referencedColumnName}`)
    }

    joinTableName(firstTableName: string, secondTableName: string): string {
        return toSnakeCase(`${firstTableName}_${secondTableName}`)
    }

    joinTableColumnName(
        tableName: string,
        propertyName: string,
        columnName?: string
    ): string {
        return `${toSnakeCase(tableName)}_${columnName || toSnakeCase(propertyName)}`
    }
}
Example #2
Source File: CMNamingStrategy.ts    From context-mod with MIT License 5 votes vote down vote up
export class CMNamingStrategy
    extends DefaultNamingStrategy
    implements NamingStrategyInterface {
    tableName(className: string, customName: string): string {
        return customName ?? className;
    }

    columnName(
        propertyName: string,
        customName: string,
        embeddedPrefixes: string[],
    ): string {
        return (
            camelCase(embeddedPrefixes.concat('').join('_')) +
            (customName ? customName : camelCase(propertyName))
        );
    }

    relationName(propertyName: string): string {
        return camelCase(propertyName);
    }

    joinColumnName(relationName: string, referencedColumnName: string): string {
        return camelCase(relationName + '_' + referencedColumnName);
    }

    joinTableName(
        firstTableName: string,
        secondTableName: string,
        firstPropertyName: string,
        secondPropertyName: string,
    ): string {
        return camelCase(
            firstTableName +
            '_' +
            firstPropertyName.replace(/\./gi, '_') +
            '_' +
            secondTableName,
        );
    }

    joinTableColumnName(
        tableName: string,
        propertyName: string,
        columnName?: string,
    ): string {
        return camelCase(
            tableName + '_' + (columnName ? columnName : propertyName),
        );
    }

    classTableInheritanceParentColumnName(
        parentTableName: any,
        parentTableIdPropertyName: any,
    ): string {
        return camelCase(parentTableName + '_' + parentTableIdPropertyName);
    }

    eagerJoinRelationAlias(alias: string, propertyPath: string): string {
        return alias + '__' + propertyPath.replace('.', '_');
    }
}
Example #3
Source File: snake-naming.strategy.ts    From bank-server with MIT License 5 votes vote down vote up
export class SnakeNamingStrategy extends DefaultNamingStrategy
  implements NamingStrategyInterface {
  tableName(className: string, customName: string): string {
    return customName ? customName : snakeCase(className);
  }

  columnName(
    propertyName: string,
    customName: string,
    embeddedPrefixes: string[],
  ): string {
    return (
      snakeCase(embeddedPrefixes.join('_')) +
      (customName ? customName : snakeCase(propertyName))
    );
  }

  relationName(propertyName: string): string {
    return snakeCase(propertyName);
  }

  joinColumnName(relationName: string, referencedColumnName: string): string {
    return snakeCase(relationName + '_' + referencedColumnName);
  }

  joinTableName(
    firstTableName: string,
    secondTableName: string,
    firstPropertyName: string,
    _secondPropertyName: string,
  ): string {
    return snakeCase(
      firstTableName +
        '_' +
        firstPropertyName.replace(/\./gi, '_') +
        '_' +
        secondTableName,
    );
  }

  joinTableColumnName(
    tableName: string,
    propertyName: string,
    columnName?: string,
  ): string {
    return snakeCase(
      tableName + '_' + (columnName ? columnName : propertyName),
    );
  }

  classTableInheritanceParentColumnName(
    parentTableName: string,
    parentTableIdPropertyName: string,
  ): string {
    return snakeCase(`${parentTableName}_${parentTableIdPropertyName}`);
  }
}
Example #4
Source File: dbconfig.ts    From squid with GNU General Public License v3.0 5 votes vote down vote up
class SnakeNamingStrategy extends DefaultNamingStrategy {
  tableName(className: string, customName?: string): string {
    return customName || `${snakeCase(className)}` // `${snakeCase(className)}s`;
  }

  columnName(
    propertyName: string,
    customName?: string,
    embeddedPrefixes: string[] = []
  ): string {
    return (
      snakeCase(embeddedPrefixes.join('_')) +
      (customName || snakeCase(propertyName))
    )
  }

  relationName(propertyName: string): string {
    return snakeCase(propertyName)
  }

  joinColumnName(relationName: string, referencedColumnName: string): string {
    return snakeCase(`${relationName}_${referencedColumnName}`)
  }

  joinTableName(firstTableName: string, secondTableName: string): string {
    return snakeCase(`${firstTableName}_${secondTableName}`)
  }

  joinTableColumnName(
    tableName: string,
    propertyName: string,
    columnName?: string
  ): string {
    return snakeCase(`${tableName}_${columnName || propertyName}`)
  }

  classTableInheritanceParentColumnName(
    parentTableName: string,
    parentTableIdPropertyName: string
  ): string {
    return snakeCase(`${parentTableName}_${parentTableIdPropertyName}`)
  }
}