WithGraphJoined returns empty values with PgBouncer and "-" in db name
See original GitHub issueObjection: 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:
- Created 3 years ago
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can confirm this happens for us. We’ve got a complex application over here but at a high level:
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.
@mwildeboer in my case this issue occurs when I use connection object, not string. So it doesn’t look like that issue.