-
Notifications
You must be signed in to change notification settings - Fork 382
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
Add Manager #2939
Add Manager #2939
Conversation
@simolus3 |
2) Move Distict to positional arg 3) Add limit as a positional arg 4) Fix _tests.dart to _test.dart for CI 5) Move all methods to base - Remove all()
@simolus3 Didn't make as many changes as I thought I would. |
I lied, I've added Let me know if should continue |
@simolus3 |
Btw, this is how server includes related data, it's really nice: |
@simolus3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay on this. The documentation looks really great, thank you a lot for the helpful snippets and explanation!
I was under the impression that this would be included in the 2.17 release 😢
Sorry about that. It's been a fairly long time since the 2.16 release, and there have been some important bugfixes that haven't been released yet so I wanted to get them out first.
But for what it's worth, I think we can do a 2.18 release shortly after merging this - this is going to be the most important feature of that release either way, so there's no reason to hold that up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work, thank you again for this huge contribution!
This looks good to me now, so as long as you don't have anything you still want to change in this PR, I'm happy to merge this.
@simolus3 |
Wohoo! 🎉 🎉 |
Warning, The following proposed API has changed from the examples shown here, see the docs for an updated representation of the manager APi.
This introduces a simpler interface to access the database.
It makes it easier to create simple, or even some complex quiries and then directly read, watch, update or delete based on
them. It should also lower the barrier of entry for developers used to simpler database alternatives.
Managers
By default every generated database will have a new field
managers
, which exposes a manager for each table in the database.Each manager is able to:
managers.categories.create((o) => o(name: 'test'))
managers.categories.bulkCreate((o) => [o(name: 'test1'),o(name: 'test2')])
managers.categories.replace(category.copyWith(name:"Important"))
Filtering & Ordering
However, the real superpower is the packaged filter and ordering builder.
Here is an example schema to show how these filters work.
Nestable
All filters can go a deeply nested as you want, traveling relations as you wish, with the manager handling all the joins automatically.
Ordering
You can compose ordering just like filters.
Although Reverse Filters arent supported :(
Like shown above, you can limit the results of a query by using the
limit
method.You can also use the
offset
argument to shift the index.For a query will all results, use
all
todoEntries.all()
OK, Now what?
Now that we have a built query we can do any of the following CRUD opperations:
I have something custom I want to do
No problem, you can add custom filters by adding an extention:
Or you can add custom filters or orderings on a table by extending the generated filterset
For example, filter on a combination of rows
Limitations
What can't this do.
Postscript
Creating this was tons of fun. My dream is that no-one find this package to scary to use. All these operations are using drift under the hood. use an ORM as a way to learn SQL. Not to avoid it.