Giter VIP home page Giter VIP logo

stop-using-orms's Introduction

"Why you should stop Using ORMs" lecture code

Getting started

Install the docker

$ npm i
$ npm run docker:start

Demonstrate Sequelize limitations

  1. see that the query does a complex query, then add required: false to the include (see https://stackoverflow.com/questions/27561915/how-can-use-left-join-at-sequelize)
  2. now see that the query does not work, and uncomment second query
  3. now open up terminal and connect to postgres, then run each query with explain analyze prefix, for example:
    explain analyze
      SELECT
        category.name as "categoryName",
        category."allowComments" as "allowComments",
        "categoryItem".name AS "categoryItemName"
      FROM category
      LEFT JOIN "categoryItem" ON 
        "categoryItem"."categoryName" = category.name
      WHERE "categoryName" = 'category-50000';
  4. demonstrate sequelize join types limits: https://qph.fs.quoracdn.net/main-qimg-50f6f1dfe991352b56da854eede1e5ff

Understanding Explain and Analyze

  • costs is measured in arbitrary unit of computation.

    Formula for these unit:

    (disk pages read * seq_page_cost) + (rows scanned * cpu_tuple_cost)

    • seq_page_cost - Sets the planner's estimate of the cost of a disk page fetch that is part of a series of sequential fetches. The default is 1.0. This value can be overridden for a particular tablespace by setting the tablespace parameter of the same name (see ALTER TABLESPACE).
    • cpu_tuple_cost - Sets the planner's estimate of the cost of processing each row during a query. The default is 0.01.
  • rows - a little tricky because it is not the number of rows processed or scanned by the plan node. It is usually less, reflecting the estimated selectivity of any WHERE-clause conditions that are being applied at the node. Ideally the top-level rows estimate will approximate the number of rows actually returned, updated, or deleted by the query.

  • width - total bytes of rows output by this plan node

  • analyze keyword will allow to ms of a real use-case (and not just theoretical)

stop-using-orms's People

Contributors

danielgolub avatar

Stargazers

Amit Novick avatar

Watchers

James Cloos avatar

stop-using-orms's Issues

Feedback

Really liked the presentation, especially since it makes a serious attempt at murdering the holy cow called ORM that has plagued too many projects.

Developers everywhere are paying the cost of investing their effort in a mini-language imposed by specific ORM / query-builder (and sometimes a self-inflicted pain of having to use the Model leaky abstraction which causes impedance mismatch) instead of just learning how to write the well-designed, most-portable SQL code.

Here is one point that I found really important:

SQL is the language of the RDBMS

These days, the best way to learn how to work with a RDBMS is through reading their documentation and going over web-indexed solutions to well-known issues written by mostly experts as answers to questions on StackOverflow or blog posts / articles. These are usually written in SQL.

Therefore, when you use an ORM / Query-builder you immediately have to face these problems:

  • Problem 1: You would be wasting time translating between an available, portable SQL solution to a non-SQL, non-portable solution written in an ORM / Query-builder mini-language?

  • Problem 2: Your code is going to be less readable. For the next developer looking at your mini-language code (could be you in a few weeks), it's going to be almost impossible to understand what it's trying to do without making a (lossy!) inverse translation back to SQL and attempting to google that.

Further Reading

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.