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

When connectionstring param used, Hostname and database name are not correctly extracted #1898

Closed
2 of 4 tasks
arrrrny opened this issue Feb 5, 2024 · 2 comments
Closed
2 of 4 tasks

Comments

@arrrrny
Copy link

arrrrny commented Feb 5, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When I try to use the connectionString param, It does not extract the "host" property and it does not connect to the DB. When I provide "host" as an additional param it works.

my connectioString is like this:
postgres://postgres:xxxxxxx@192.168.1.23:5432/zingo

TypeOrmModule.forRootAsync({
  useFactory: () => ({
    type: 'postgres',
    connectionString: config.postgresUri,
    autoLoadEntities: true,
    synchronize: false,
  }),
}),

I get the error
[Nest] 32864 - 02/05/2024, 5:03:26 PM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
AggregateError:
at internalConnectMultiple (node:net:1116:18)
at afterConnectMultiple (node:net:1680:7)

When I use it like this by specifying the "host", it connects to the DB, however instead of connecting to the DB "zingo" from the connection string, it tries to connect to the computer name

TypeOrmModule.forRootAsync({
  useFactory: () => ({
    type: 'postgres',
    host:192.168.1.23,
    connectionString: config.postgresUri,
    autoLoadEntities: true,
    synchronize: false,
  }),
}),

[Nest] 33017 - 02/05/2024, 5:05:21 PM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (6)...
error: database "ahmettok" does not exist

When I have like below, it works fine.

TypeOrmModule.forRootAsync({
  useFactory: () => ({
    type: 'postgres',
    host:192.168.1.23,
    connectionString: config.postgresUri,
    autoLoadEntities: true,
    synchronize: false,
    database:'zingo'
  }),
}),

Minimum reproduction code

https://github.com/do_i_really_need_this

Steps to reproduce

No response

Expected behavior

host should be extracted from the connectionstring parameter and should not require to be additionally provided. Also database name should be correctly extracted from the connection string

Package version

10.0.0

NestJS version

10.2.7

Node.js version

21.6.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@arrrrny arrrrny changed the title When connectionstring param used, Hostname is not loaded from the connection string When connectionstring param used, Hostname and database name are not correctly extracted Feb 5, 2024
@micalevisk
Copy link
Member

micalevisk commented Feb 5, 2024

Please provide a minimum reproduction repository. You can start one by running npm init nest in your terminal

why reproductions are required

@arrrrny
Copy link
Author

arrrrny commented Feb 5, 2024

@micalevisk Thanks for the heads up. Issue was strangely because of the "cody" AI code completion tool and it automatically populated the field "connectionString" rather than the correct field "url" Since additional fields were allowed on that config, typescript did not give an error either. It works fine as

TypeOrmModule.forRootAsync({
  useFactory: () => ({
    type: 'postgres',
    url: config.postgresUri,
    autoLoadEntities: true,
    synchronize: false
  }),
})

@arrrrny arrrrny closed this as completed Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants