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

[ENHANCEMENT]: Implementation of distinct #119

Open
Kyryus opened this issue Dec 12, 2024 · 4 comments
Open

[ENHANCEMENT]: Implementation of distinct #119

Kyryus opened this issue Dec 12, 2024 · 4 comments

Comments

@Kyryus
Copy link

Kyryus commented Dec 12, 2024

Feature Description

Hello I am not sure it is really possible as I think "distinct" is not existing in all SQL language but do you plan to implement it ?

I see that in your example you use it with RAW queries only.

Thank you for your feedback

@lroal
Copy link
Member

lroal commented Dec 12, 2024

I think the aggregate function (groupBy) will work the same as DISTINCT.
In the example below, it will do a groupBy on customerId and customerName. If you remove the numberOfLines and totals, you have DISTINCT.

import map from './map';
const db = map.sqlite('demo.db');

getAggregates();

async function getAggregates() {
  const orders = await db.order.aggregate({
    where: x => x.orderDate.greaterThan(new Date(2022, 0, 11, 9, 24, 47)),
    customerId: x => x.customerId,
    customerName: x => x.customer.name,
    numberOfLines: x => x.count(x => x.lines.id),
    totals: x => x.sum(x => lines.amount)    
  });
}

@lroal
Copy link
Member

lroal commented Dec 12, 2024

Will it work for you ?
I should write a note in the documentation about DISTINCT.

@Kyryus
Copy link
Author

Kyryus commented Dec 12, 2024

Hello Iroal, thank you for the fast answer.

I know that the GROUP is the same but I read somewhere that for huge quantity of data GROUP BY is less efficient. However for little quantity of data, there is no difference of performance.

Anyway I think that using RAW query for this specific case is not absurd.

@lroal
Copy link
Member

lroal commented Dec 13, 2024

I can always add distinct. Much of it will just be copy paste from the aggregate function.

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