Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SQLAlchemy Core: Pythonic SQL, no strings attached

SQLAlchemy Core: Pythonic SQL, no strings attached

SQLAlchemy is more than just an ORM, it's a complete way to integrate SQL queries into Python code. A lightning talk.

Danielle Brook-Roberge

June 04, 2016
Tweet

More Decks by Danielle Brook-Roberge

Other Decks in Programming

Transcript

  1. SQLAlchemy ORM • The SQLAlchemy library is best known for

    its ORM (object-relational mapper) capabilities. • This provides an easy-to-use method for accessing the contents of a database. • With an ORM’d class, we can just retrieve instances from a database, work with them ignoring the database aspect, and then commit them back to the database when we’re done.
  2. ORM Disadvantages • ORM code is easy to write but

    easy to make inefficient. • In the previous example, the entire contents of the TodoItem object are retrieved from the database, even though only the done column is used. • We would like to be able to make updates directly on the database server, and to fetch only the necessary columns for a large operation.
  3. SQLAlchemy Core • SQLAlchemy also provides a Core library, that

    maps directly from Python statements to SQL queries. • This allows SQL statements to be specified in such a way that they can be verified as part of the Python code, e.g. by a linter. • This permits selective transfers of data, and mutating operations done purely inside the DBMS.