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

Let's Build an ORM

Greg Back
February 10, 2019

Let's Build an ORM

Applications rely on data, and relational databases are a convenient way to organize structured information. Object-relational mappers like SQLAlchemy and Django's ORM are complex libraries, but they aren't black magic. De-mystify some of the magic as we build a (basic) ORM in under an hour.

Greg Back

February 10, 2019
Tweet

More Decks by Greg Back

Other Decks in Programming

Transcript

  1. Giving a talk 1. Think of a topic 2. Submit

    Proposal 3. Proposal accepted 4. Panic 5. Write talk
  2. (Potential) Responsibilities of an ORM • create database • define

    tables • define fields ◦ size/length ◦ nullable ◦ default values • define foreign keys • define indices • define relationships ◦ one-to-many ◦ many-to-many ◦ one-to-one ◦ inverse relationships • define stored procedures • class inheritence • caching • transactions ◦ commit ◦ rollback ◦ nested transactions • support sqlite • support MySQL • support PostgreSQL • support Oracle • support MS SQL Server • prevent SQL injection • remain performant • support multiple clients • use multiple databases • error handling • logging • create tables • insert data ◦ convert data types ◦ validate data • retrieve data ◦ support joins ◦ order results ◦ subqueries ◦ nested queries ◦ lazy loading ◦ eager loading • update data ◦ by ID ◦ using filters • delete data ◦ by ID ◦ using filters • cascading operations • bulk operations
  3. Responsibilities of our ORM • create database • define tables

    • define fields ◦ size/length ◦ nullable ◦ default values • define foreign keys • define indices • define relationships ◦ one-to-many ◦ many-to-many ◦ one-to-one ◦ inverse relationships • define stored procedures • class inheritence • caching • transactions ◦ commit ◦ rollback ◦ nested transactions • support sqlite • support MySQL • support PostgreSQL • support Oracle • support MS SQL Server • prevent SQL injection • remain performant • support multiple clients • use multiple databases • error handling • logging • create tables • insert data ◦ convert data types ◦ validate data • retrieve data ◦ support joins ◦ order results ◦ subqueries ◦ nested queries ◦ lazy loading ◦ eager loading • update data ◦ by ID ◦ using filters • delete data ◦ by ID ◦ using filters • cascading operations • bulk operations • create database • define tables • define fields • define foreign keys • create tables • insert data • retrieve data • support sqlite