Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Add how-to guide on integrating with Tortoise ORM #16

Closed
florimondmanca opened this issue Nov 20, 2018 · 14 comments
Closed

Add how-to guide on integrating with Tortoise ORM #16

florimondmanca opened this issue Nov 20, 2018 · 14 comments
Assignees
Labels
docs Documentation improvements or other changes
Milestone

Comments

@florimondmanca
Copy link
Member

florimondmanca commented Nov 20, 2018

Complementary to #4 , we should write how-to guides explaining how to configure and use an async database client in order to perform database queries asynchronously in a Bocadillo app.

Note: this is a temporary but reasonable solution waiting for a sane async ORM to come around, like Tortoise.

Available async clients for popular databases are:

If possible and relevant, we should also provide snippets that abstract away common logic such as connecting to the database or handling cursors, so that app-side code looks something like:

from asyncdb import query  # <- snippet

async def get_products(req, res):
    results = await query('SELECT id, name, price FROM products;')
    # do something with `results`

Guidelines on contributing documentation have been added to CONTRIBUTING.md. Feel free to reach out to discuss any ideas!

Edit (Dec 19th): it actually seems like a good idea to make databases more approachable and suggest an integration with Tortoise ORM in the how-to guide.

@florimondmanca florimondmanca added the docs Documentation improvements or other changes label Nov 20, 2018
@florimondmanca
Copy link
Member Author

@alin23 If you're interested in giving the asyncpg guide a go, I'd be more than happy to see what you come up with based on your past experience! 👍

@florimondmanca florimondmanca changed the title Guidelines for using async database clients Add how-to guides for using async database clients Nov 20, 2018
@florimondmanca florimondmanca added the available Come and grab it! label Nov 20, 2018
@alin23
Copy link
Contributor

alin23 commented Nov 21, 2018

@florimondmanca I'd be glad to help! Probably this weekend as my daily job is quite demanding nowadays. In the meantime, can you take a look here: #3 (comment)
I'd really like to see that PR merged ^_^

@florimondmanca
Copy link
Member Author

Thanks @alin23.

I'd really like to see that PR merged ^_^

Just a note: keep in mind that Bocadillo is still in alpha, so I wouldn't advise using it in production (if that's what you're planning to do). Beyond possible API changes, there are still some important aspects that haven't been dealt with yet, such as security. 😉

@florimondmanca
Copy link
Member Author

Hi @alin23, have you got any chance to look at the asyncpg guide yet? 😊

@alin23
Copy link
Contributor

alin23 commented Dec 3, 2018

Nope, not yet. The company I'm working with is on a last-mile talk with investors and I have to make sure everything's on track here. So I won't have much time for open source work these weeks.

Sorry for overpromising, I'd really like to contribute to this but I don't have the time yet

@florimondmanca
Copy link
Member Author

I've just read more thoroughly through the Tortoise ORM docs and I thought — Tortoise may actually be sufficient for this how-to guide. At least, it's a more user-friendly advice than resorting to a raw client, and it will be very familiar to those who have used Django in the past.

I'm leaving a link to their Get started guide here for reference. Might be worth adapting it to show how to setup the DB, create a model and use it in some views.

@alin23
Copy link
Contributor

alin23 commented Dec 11, 2018

It definitely looks much better than raw sql ^_^
I think we need a startup event that runs after the loop is initialized but before the server is started to allow initialization for this. Do we have anything like this?

@florimondmanca
Copy link
Member Author

We don't yet, but that's definitely doable (at worst wrapping around Starlette's event handling). Plus I've been thinking we'd need this at some point.

It looks like opening connections needs the startup event and cleaning up needs shutdown.

If you're feeling like it you can open a feature request for that? :)

@alin23
Copy link
Contributor

alin23 commented Dec 11, 2018

Sure!

@florimondmanca
Copy link
Member Author

Hi @alin23, #62 (startup and shutdown events) has just been merged. 👍

@alin23
Copy link
Contributor

alin23 commented Dec 17, 2018

Awesome work! On 19th I'm getting back from a trip and I can hop on this db stuff.

@florimondmanca florimondmanca changed the title Add how-to guides for using async database clients Add how-to guide on integrating with Tortoise ORM Dec 19, 2018
@florimondmanca
Copy link
Member Author

Just for my information, have you been working on this @alin23? I just found myself in a mood to tackle this today, with the second goal of showing an example "blog" app as described in #25.

@alin23
Copy link
Contributor

alin23 commented Jan 12, 2019

Go for it! I'm buried in work and side-projects, I won't be able to get to it soon enough. 😞

@florimondmanca
Copy link
Member Author

No worries, understood!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
docs Documentation improvements or other changes
Projects
None yet
Development

No branches or pull requests

2 participants