Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: DataSource is not a constructor #371

Open
goodstemy opened this issue Dec 11, 2023 · 1 comment
Open

TypeError: DataSource is not a constructor #371

goodstemy opened this issue Dec 11, 2023 · 1 comment

Comments

@goodstemy
Copy link

Describe the bug

Trying to write tests based on this example using createTypeormDataSource.

 FAIL  src/controllers/order/order.service.spec.ts
  Order module
    ✕ Should work

  ● Order module › Should work

    TypeError: DataSource is not a constructor

      50 |     })
      51 |
    > 52 |     const conn = await db.adapters.createTypeormDataSource({
         |                                    ^
      53 |       type: 'postgres',
      54 |       entities: [Wallet, User, UserRole, Role, RolePermission, Permission, Session, UserSettings, ProductMiddleWallet, Product, NetworkCurrency, Network, Currency],
      55 |     });

      at Adapters.createTypeormDataSource (node_modules/pg-mem/src/adapters/adapters.ts:208:25)
      at Object.createTypeormDataSource (src/controllers/order/order.service.spec.ts:52:36)

Also createTypeormConnection works fine beside another problem from my other issue.

To Reproduce

    const db = newDb({
      autoCreateForeignKeyIndices: true,
    });

    db.public.registerFunction({
      implementation: () => 'test',
      name: 'current_database',
    });

    db.public.registerFunction({
      name: 'version',
      args: [],
      returns: DataType.text,
      implementation: (x) => `hello world: ${x}`
    })

    db.registerExtension('uuid-ossp', (schema) => {
      schema.registerFunction({
        name: 'uuid_generate_v4',
        returns: DataType.uuid,
        implementation: v4,
        impure: true
      })
    })

    const conn = await db.adapters.createTypeormDataSource({
      type: 'postgres',
      entities: [Wallet, User, UserRole, Role, RolePermission, Permission, Session, UserSettings, ProductMiddleWallet, Product, NetworkCurrency, Network, Currency],
    });

pg-mem version and another deps

"pg-mem": "^2.7.2",
"typeorm": "0.2.45",
"pg": "^8.7.3",
@goodstemy
Copy link
Author

Actually problem because typeorm added DataSource class only in version 0.3.0 and higher.

I think really matter update package json and update peer deps with 0.3.0 version of typeorm.

  "peerDependencies": {
    "knex": ">=0.20",
    "pg-promise": ">=10.8.7",
    "slonik": ">=23.0.1",
    "typeorm": ">=0.2.29" // here
  },

And I think really matter to update wiki for usage pg-mem with typeorm.

https://github.com/oguimbal/pg-mem/wiki/Libraries-adapters#-typeorm

Change createTypeormConnection -> createTypeormDataSource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant