-
-
Notifications
You must be signed in to change notification settings - Fork 518
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
Limit filter option for querying Collection #334
Comments
I am not against this, but the problem is that semi-initialized collection can't be used for anything more than reading, so we will need to introduce some read only collection wrapper to be used instead. The problem is already there, as you are able to use filtering on collections. Are you talking just about the |
Agreed with @B4nan that this will very likely cause bugs if 1 part of your application initializes the collection with the "only load 50" option, but then some other part of your application processes some business logic (like "sum all my account transactions") with the "great it's already loaded collection, I'll skip calling If you have too many rows to pull into memory as a Alternatively, Mikro could introduce a concept of |
Collections now have a `matching` method that allows to slice parts of data from a collection. By default, it will return the list of entities based on the query. We can use the `store` boolean parameter to save this list into the collection items - this will mark the collection as `readonly`, methods like `add` or `remove` will throw. ```ts const a = await em.findOneOrFail(Author, 1); // only loading the list of items const books = await a.books.matching({ limit: 3, offset: 10, orderBy: { title: 'asc' } }); console.log(books); // [Book, Book, Book] console.log(a.books.isInitialized()); // false // storing the items in collection const tags = await books[0].tags.matching({ limit: 3, offset: 5, orderBy: { name: 'asc' }, store: true, }); console.log(books); // [BookTag, BookTag, BookTag] console.log(a.books.isInitialized()); // true console.log(a.books.getItems()); // [BookTag, BookTag, BookTag] ``` Closes #334
Collections now have a `matching` method that allows to slice parts of data from a collection. By default, it will return the list of entities based on the query. We can use the `store` boolean parameter to save this list into the collection items - this will mark the collection as `readonly`, methods like `add` or `remove` will throw. ```ts const a = await em.findOneOrFail(Author, 1); // only loading the list of items const books = await a.books.matching({ limit: 3, offset: 10, orderBy: { title: 'asc' } }); console.log(books); // [Book, Book, Book] console.log(a.books.isInitialized()); // false // storing the items in collection const tags = await books[0].tags.matching({ limit: 3, offset: 5, orderBy: { name: 'asc' }, store: true, }); console.log(tags); // [BookTag, BookTag, BookTag] console.log(books[0].tags.isInitialized()); // true console.log(books[0].tags.getItems()); // [BookTag, BookTag, BookTag] ``` Closes #334
…1502) Collections now have a `matching` method that allows to slice parts of data from a collection. By default, it will return the list of entities based on the query. We can use the `store` boolean parameter to save this list into the collection items - this will mark the collection as `readonly`, methods like `add` or `remove` will throw. ```ts const a = await em.findOneOrFail(Author, 1); // only loading the list of items const books = await a.books.matching({ limit: 3, offset: 10, orderBy: { title: 'asc' } }); console.log(books); // [Book, Book, Book] console.log(a.books.isInitialized()); // false // storing the items in collection const tags = await books[0].tags.matching({ limit: 3, offset: 5, orderBy: { name: 'asc' }, store: true, }); console.log(tags); // [BookTag, BookTag, BookTag] console.log(books[0].tags.isInitialized()); // true console.log(books[0].tags.getItems()); // [BookTag, BookTag, BookTag] ``` Closes #334
Is your feature request related to a problem? Please describe.
I'm worried about relations that could become large with the collection.init() function using postgres. Looked through the code and it seems like a relatively simple change. I don't mind helping out with this if you'd like as this is something I would like to have and really like this project.
could be change to:
Describe the solution you'd like
drivers/DatabaseDriver.ts
This should change the DatabaseDriver functions to all except Filter, this could make the function arguments more dynamic and extendible for custom configuration. Which would cause a breaking change unfortunately, unless you had variants for the functions inputs until the next version.
Let me know your thoughts!
The text was updated successfully, but these errors were encountered: