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

Get count of records #662

Open
sawilde opened this issue Oct 23, 2021 · 3 comments
Open

Get count of records #662

sawilde opened this issue Oct 23, 2021 · 3 comments

Comments

@sawilde
Copy link

sawilde commented Oct 23, 2021

Description

No obvious ways to get a count of records matching some criteria using Isotope

Expected behavior

A method that would allow someone to call the equivalent of select count(*) where ...; obviously restricted to the type of record

see https://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/CountingDataSelect.html

eg I was thinking something along the lines of

const expr = isotope
    .getQueryBuilder()
    .where('`active` = ? and `submitDate` >= ?', true, startDate);

const total = await isotope.count(expr);

Actual behavior

As far as I can tell, I would need to pull all the items to get a count which seems wasteful.

Package versions

  • isotopes: 0.6.1
  • aws-sdk: 2.987.0
@sawilde
Copy link
Author

sawilde commented Oct 23, 2021

So I manage to hack something together and get a count and that is when I realised that when you create a client

const isotope = new Isotope<Thing>({
  domain: 'mydomain',
  key: 'id',
});

when you pull data via select you are not limited by the type and if you are not careful you could end up bleeding data from one type into the other eg if you filter by a field that is shared by both types causing data from records containing both types to be returned and then transformed into looking like the type in your client.

You are sort of limited to one type per domain to be safe.

@sawilde
Copy link
Author

sawilde commented Oct 24, 2021

^ for the above I have spiked a possible solution and created a draft PR for you to look at

#663

@squidfunk
Copy link
Owner

Note that Isotopes is more or less a client implementing CRUD, so currently only whole records are returned. While the IsotopeClient.select signature should allow for arbitrary types to be returned, I'm not sure how this fits into the interface of the Isotope class. It may be out-of-scope. I'll look into it when I find some time.

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

No branches or pull requests

2 participants