Skip to content

Problems with knex using postgres driver #20

@jtiala

Description

@jtiala

I encountered some problems while trying to use this library with apollo-server setup using PostgreSQL as database and knex. My setup doesn't use objection ORM, it just calls knex queries straight from the resolver.

I forked the library and added posgres driver to isolate the issue from my setup. I created a new table, cities, since my initial problem was concerning a calculated column, which shows distance between coordinates in the database compared to coordinates in the query.

Most of the added code is here. The file contains detailed comments on the problem. I also added notes to the readme on how to run dockerized posgres to test this on. By the way, this can not be tested on sqlite since it doesn't have the necessary math functions to calculate distances.

I encountered two problems.

  1. .groupBy('id') is needed when selecting the columns using .select(). Even though the exact same query is generated with .select(['*']) and omitting the select altogether. When driving the sqlite driver, this problem doesn't occur. See implementation2 in the file linked before.
  2. When adding the custom column to the select array, it works fine when using only first pagination parameter. The column appears in the results and results can be sorted based on the calculated column. Using anything else than first breaks the query. See implementation3.

Any idea what might be causing this?

If you would like to include the test cases in the repo, I can clean them up and do a PR. There are no tests tho, didn't have time to setup postgres tests. I also added some general notes on the readme, feel free to copy them if you feel so :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions