Skip to content

Commit

Permalink
Sopel 7: last-minute update to DB API changes backward compatibility
Browse files Browse the repository at this point in the history
A lot fewer old plugins will need to be updated now.
  • Loading branch information
dgw committed Jan 24, 2020
1 parent aadde30 commit 6671a93
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions _upgrading/sopel-7.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,31 @@ we just provide the tools you need to get started.
### Accessing the database

While Sopel's [migration to SQLAlchemy](#database-support) doesn't affect
*most* of the `bot.db` API, some plugins that make use of the more direct
methods might need to be rewritten for Sopel 7. Non-exhaustively:

* `bot.db.connect()` now returns a SQLAlchemy `Connection` object that
doesn't have all the same attributes as the one provided by native `sqlite`
(e.g. `connection.cursor`)
* `bot.db.execute()` *should* still return an object that behaves like a
`Cursor`, but since it's actually a SQLAlchemy wrapper not everything is
guaranteed to work exactly the same
* `bot.db.get_uri()` hasn't functionally changed, but it's important to
remember that it now *might* return a URI with a non-`sqlite` dialect
*most* of [the `bot.db` API][docs-db], some plugins that make use of the more
direct methods might need to be rewritten for Sopel 7. Non-exhaustively:

* [`bot.db.execute()`][docs-db-execute] *should* still return an object that
behaves like a `Cursor`, but since it's actually a SQLAlchemy wrapper not
everything is guaranteed to work exactly the same
* [`bot.db.get_uri()`][docs-db-get_uri] hasn't functionally changed, but it's
important to remember that the returned URI *might* not point to SQLite
* [`bot.db.connect()`][docs-db-connect] is likewise functionally unchanged,
except that it can now return a non-SQLite DBAPI connection object,
potentially one with behavior different from the SQLite connections always
returned in older versions

We recommend that authors of plugins which use a raw database connection from
`bot.db.connect()` aim to rewrite their code so it uses the ORM approach and
[`bot.db.session()`][docs-db-session] instead. In the interim, it never hurts
to update your plugin's documentation to warn users that non-SQLite databases
haven't been tested, or make sure the plugin is marked as compatible with Sopel
<7.0 only until it can be tested and/or updated.

[docs-db]: /docs/db.html
[docs-db-connect]: /docs/db.html#sopel.db.SopelDB.connect
[docs-db-execute]: /docs/db.html#sopel.db.SopelDB.execute
[docs-db-get_uri]: /docs/db.html#sopel.db.SopelDB.get_uri
[docs-db-session]: /docs/db.html#sopel.db.SopelDB.session

### Managing URL callbacks

Expand Down

0 comments on commit 6671a93

Please sign in to comment.