question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WithGraphJoined returns empty values with PgBouncer and "-" in db name

See original GitHub issue

Objection: 2.1.5 DB: Postgres 11 @ DigitalOcean Pool: PgBouncer

Here’s basic example

class BaseModel extends Model {
  // Objection Model Configs
  static get modelPaths() {
    return [__dirname];
  }
  static get tableName() {
    return this.name;
  }
  static get useLimitInFirst() {
    return true;
  }
  static get timestamp() {
    return true;
  }
}
const Plugins = compose(Guid(), Timestamps());

class Foo extends Plugins(BaseModel) {
  static get tableName() {
    return 'foos';
  }
  static get timestamp() {
    return true;
  }
  static get jsonSchema() {
    return {
      properties: {
        id: {
          type: 'string',
          format: 'uuid',
        },
        barId: {
          type: 'integer',
        },
        bazId: {
          type: 'integer',
        },
      },
      required: ['barId', 'bazId'],
      type: 'object',
    };
  }

  static get relationMappings() {
    const Bar = require('./Bar');
    const Baz = require('./Baz');
    return {
      bar: {
        relation: Model.BelongsToOneRelation,
        modelClass: Bar,
        join: {
          from: 'foo.barId',
          to: 'bar.id',
        },
      },
      baz: {
        relation: Model.BelongsToOneRelation,
        modelClass: Baz,
        join: {
          from: 'foo.bazId',
          to: 'baz.id',
        },
      },
    };
  }
}

When I use direct database connection (e.g. on DO it’s on port 25060), objection generates valid query from this one:

Foo.query().withGraphJoined('[bar, baz]').where({ 'bar.id': 1234 }).debug();
select "foos"."id" as "id", "foos"."created_at" as "created_at", "foos"."updated_at" as "updated_at", "foos"."baz_id" as "baz_id", "foos"."bar_id" as "bar_id", "baz"."id" as "baz:id", "baz"."name" as "baz:name", "baz"."created_at" as "baz:created_at", "baz"."updated_at" as "baz:updated_at", "bar"."id" as "bar:id", "bar"."created_at" as "bar:created_at", "bar"."updated_at" as "bar:updated_at" from "foos" left join "bazs" as "baz" on "baz"."id" = "foos"."baz_id" left join "bars" as "bar" on "bar"."id" = "foos"."bar_id" where "bar"."id" = ?

When I switch config to use pgbouncer (just change port to 25061 and database name that contains my-db that’s mapped by pgbouncer to correct database e.g my), then it generates wrong one:

select "foos".* from "foos" left join "bazs" as "baz" on "baz"."id" = "foos"."baz_id" left join "bars" as "bar" on "bar"."id" = "foos"."bar_id" where "bar"."id" = ?

NOTE: withGraphFetched works well in both cases, so it’s not bouncer or database issue.

UPD: looks like the problem is with - in database names.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
mashaalmemoncommented, Nov 26, 2022

I can confirm this happens for us. We’ve got a complex application over here but at a high level:

  • Direct connection to database works great.
  • Connection through PgBouncer results in issues with withGraphJoined queries, where the query seems to execute but only the rows from the joined tables do not get returned.

The only thing changed is post/database name as those are the things different between the direct connection vs PgBouncer connection. Otherwise code/environment are exactly the same.

0reactions
SkeLLLacommented, Jun 2, 2020

@mwildeboer in my case this issue occurs when I use connection object, not string. So it doesn’t look like that issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

postgres query returns empty object when using inner join
I use node-postgres to get role name from roles table using role_id foreign key on users table. I executed this query in psql...
Read more >
Eager Loading Methods | Objection.js - GitHub Pages
Returns the object representation of the relation expression passed to either withGraphFetched or withGraphJoined . See this section for more examples and ...
Read more >
Vincit/objection.js - Gitter
Just query all the data you need to return the response. If it is easiest to do by .withGraphFetched in the start of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found