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

Doesn't support distinctOn and other database specific methods #7

Closed
ZeRego opened this issue Oct 12, 2021 · 2 comments · Fixed by #10
Closed

Doesn't support distinctOn and other database specific methods #7

ZeRego opened this issue Oct 12, 2021 · 2 comments · Fixed by #10

Comments

@ZeRego
Copy link

ZeRego commented Oct 12, 2021

Note that I'm going to talk about the distinctOn method but there are others methods in the same situation.

We are using distinctOn which is only supported for Postgres.

I get the error:

'.distinctOn() is currently only supported on PostgreSQL'

This is because the mock client extends the basic knex client. This client uses the basic query compiler, that has the implementation:

  // node_modules/knex/lib/query/querycompiler.js
  distinctOn(value) {
    throw new Error('.distinctOn() is currently only supported on PostgreSQL');
  }

Work around I found for this problem:

class MockClientWithDistinctOn extends MockClient {
    queryCompiler(builder: any) {
        const queryCompiler = super.queryCompiler(builder);
        queryCompiler.distinctOn = (value: any) => '';
        return queryCompiler;
    }
}

...
const database =  knex({ client: MockClientWithDistinctOn }

Maybe we could have a MockClient for each supported client. If this is to much we could just return an empty string for these methods.

@felixmosh
Copy link
Owner

I need to check for possible solutions...
I don't want to stub each one of the specific functions.

@felixmosh
Copy link
Owner

Added in v1.6.0, thank you for reporting this issue, now the lib supports a specific dialects :]

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

Successfully merging a pull request may close this issue.

2 participants