-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We're using it fairly minimally: essentially still writing manual queries, but now using SQLAlchemy to handle placeholder binding which is nicer, and portable. The API now goes like this: - `db.get_conn()` returns a connection from the connection pool; web.appdb, in particular, is a preloaded, app-context connection object that most code uses. - `web.query()` does an SQLAlchemy 'text' query, which is almost like regular prepare+bind+execute, except that it always uses `:name` for placeholders and binds using `name=...` keyword arguments. That is, instead of: db.execute("SELECT token FROM rooms WHERE id = ?", (123,)) we now do: query("SELECT token FROM rooms WHERE id = :id", id=123) or equivalently: db.query(appdb, "SELECT token FROM rooms WHERE id = :id", id=123) (the latter version is more useful where an app context doesn't exist and you need to pass in some other conn, such as is now done in __main__). - transactions are now controlled with a `with appdb.begin_nested():` context, replacing the custom nested tx handler I made for sqlite. We *could* start using more advanced SQLAlchemy query composition, but that seems like more of a pain rather than something useful. (I *don't* want to use SQLAlchemy ORM, because in my experience ORM just gets in the way as soon as you want non-trivial database structure, which we have here). This will allow us to (easily) add postgresql support. (Other database are probably a no-go: SQLite has long looked up to postgresql for features and syntax and so the two are very similar dialects).
- Loading branch information
Showing
8 changed files
with
494 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.