Skip to content

CLI does not support async DataSource #8914

@anton-pavlov-personal

Description

@anton-pavlov-personal

Issue Description

Starting from the 0.3.0 version, CLI requires to specify the file with DataSource instance instead of ormconfig. When I am trying to export async created DataSource it fails

Expected Behavior

Command ran successfully

Actual Behavior

Command failed with error: Error: Given data source file must contain export of a DataSource instance

Steps to Reproduce

Have your DataSource defined in the file:

const buildDataSource = async () => {
  // Provided config-like functionality just for example, it will fail anyway with just async function
  const dbConfig = await config.get('database');

  return new DataSource({
    type: 'mysql',
    host: dbConfig.host,
    port: 3306,
    username: dbConfig.username,
    password: dbConfig.password,
    database: dbConfig.database,
    logging: true,
    entities: typeormEntities,
    migrations: [ './src/components/database/migrations/**/*.ts' ]
  })
};

export default buildDataSource();

This works though:

const buildDataSource = () => {
  return new DataSource({
    type: 'mysql',
    host: '127.0.0.1',
    port: 3306,
    username: 'test',
    password: 'test',
    database: 'test',
    logging: true,
    entities: typeormEntities,
    migrations: [ './src/components/database/migrations/**/*.ts' ]
  })
};

export default buildDataSource();

My Environment

Dependency Version
Operating System Ubuntu 20.04.4 LTS
Node.js version v16.13.0
Typescript version 4.6.3
TypeORM version 0.3.4

Relevant Database Driver(s)

I tested with mysql only but I do not think it is a driver problem at all

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql yes
nativescript no
oracle no
postgres no
react-native no
sap no
spanner no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions