s3-db icon indicating copy to clipboard operation
s3-db copied to clipboard

.find() for the subCollection

Open vanerleo opened this issue 7 years ago • 14 comments

calling .find() for the subcollection returns the objects of the parent collection:

const companyTable = await database.getCollection('companies');
const table = companyTable.subCollection(`${company.id}-${TABLE_NAME}`);
const documentReferences = await table.find();

documentReferences would contain the files from 'companies'

vanerleo avatar Jul 26 '18 08:07 vanerleo

the issue i think is in AWSProvider : 124

  if(fqn.name.indexOf('/')!==-1) params.Delimiter = '/';
        if(startsWith) params.Prefix = fqn.name.indexOf('/')===-1 ? startsWith : `{fqn.name.substring(fqn.name.indexOf('/')+1}/${startsWith}`;

vanerleo avatar Jul 26 '18 08:07 vanerleo

Adding to this issue, it would be useful if subCollections were cached in some way. I am not sure of your initial thoughts behind them, but from my perspective it would be great if they could inherit as much of a collection functionality as possible

keithburrows avatar Jan 15 '19 02:01 keithburrows

Are you both still using subCollections? I never really put a ton of effort into this as there only seemed to be a couple cases. 3.X was released just now so want to gauge if this is something i should address in the new version.

matt-filion avatar Mar 29 '19 21:03 matt-filion

yes, sub collections are useful

vanerleo avatar Mar 29 '19 23:03 vanerleo

How do you use them? Are you iterating through a lot of records, or doing CRUD operations on an item within the collection?

I'm thinking about updating the way that find works to use the iterator pattern so you can keep going without having to use a continuation token.

matt-filion avatar Mar 30 '19 01:03 matt-filion

Storing related data for parent entity under that entity, IE : CompanyID => Users this way clean up and reporting is "self contained"

vanerleo avatar Mar 30 '19 07:03 vanerleo

I am using them for monitoring a (work)flow of lambdas run (as I go tired of the dynamodb restrictions).
Each lambda run instance currently is a sub collection.
Looking at the new documentation and what you have commented, I think that subCollections do not exist in v3 at the moment?

keithburrows avatar Mar 31 '19 22:03 keithburrows

Not yet. Should be there this week ish. Just want to be sure that I consider this feature properly. I built it without use case of my own.

On Sun, Mar 31, 2019, 3:56 PM keithburrows [email protected] wrote:

I am using them for monitoring a (work)flow of lambdas run (as I go tired of the dynamodb restrictions). Each lambda run instance currently is a sub collection. Looking at the new documentation and what you have commented, I think that subCollections do not exist in v3 at the moment?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/matt-filion/s3-db/issues/27#issuecomment-478393423, or mute the thread https://github.com/notifications/unsubscribe-auth/ABUplBBk97-jOB15gif0z6NDxVypXDG1ks5vcT01gaJpZM4VhZbr .

matt-filion avatar Mar 31 '19 23:03 matt-filion

Alright, I've got a branch for this.

https://github.com/matt-filion/s3-db/tree/3.0.3_child_collections

PR if you feel like reviewing. https://github.com/matt-filion/s3-db/pull/38

Should work more or less the way it did before. I've removed any knowledge of delimiters and left it up to the caller to provide the prefix exactly as desired.

From the docs


subCollection(prefix): Collection

Creates a new collection where all operations will execute with the prefix in front of the id's used. So if the prefix is /users/ then when .load('1234') is called the request will result in an ID lookup for /users/1234. Similarly, all objects saved will have the prefix applied when the ID is generated by the save operation, or, when an ID is provided and it does not startWith() the configured prefix.

matt-filion avatar Apr 01 '19 16:04 matt-filion

Any thoughts on this ^^

matt-filion avatar Apr 02 '19 22:04 matt-filion

thats what i'd be expecting will try to test it soon

vanerleo avatar Apr 02 '19 23:04 vanerleo

KK. Only change i need to make is increase the version properly to 3.1.0 instead of 3.0.3 but otherwise I think it seems good to go.

matt-filion avatar Apr 02 '19 23:04 matt-filion

Sorry, I am not going to get to this for a short while as I don't think I currently have time to upgrade to 3.n. Thanks for all the effort though as I definitely will in the next couple of weeks.

keithburrows avatar Apr 02 '19 23:04 keithburrows

Bump on ^^. Want to put some effort towards this project over the weekend and be nice to have this to roll into mainline.

matt-filion avatar Apr 10 '19 15:04 matt-filion