Skip to content

Bind parameters #998

Closed
Closed

Description

@jesslilly

Sequelize is awesome, but I have an enhancement idea. Bind parameters. I am using mostly sequelize for my database queries, but I had a big nasty query that was taking too long. So I changed the code to use node-sqlite3 instead and use bind variables. Now the query is much faster. Could you implement bind variables in sequelize?

Activity

  1. janmeier commented on Dec 9, 2013

    @janmeier
    Member
  2. jesslilly commented on Dec 9, 2013

    @jesslilly
    Author

    Very good, but I was thinking that you could use bind parameters for all queries that touch the database.

    For example:

    Project.find(123).success(function(project) {
      // project will be an instance of Project and stores the content of the table entry
      // with id 123. if such an entry is not defined you will get null
    })
    

    Will generate SQL:

    SELECT * FROM Projects WHERE ID = ?
    Bind Parameter 123
    

    This query execution plan could be reused by the RDBMS.

  3. jesslilly commented on Dec 9, 2013

    @jesslilly
    Author

    I can't find a button to re-open.

  4. mickhansen commented on Dec 9, 2013

    @mickhansen
    Contributor

    Why would you need bind parameters for anything other than raw queries?

  5. mickhansen commented on Dec 9, 2013

    @mickhansen
    Contributor

    Oh, are you thinking that Sequelize should use prepared statements?

  6. mickhansen commented on Dec 9, 2013

    @mickhansen
    Contributor

    Ah, @janmeier explained it to me. We probably won't be able to support this, since it's not supported by the drivers it seems :)

  7. mickhansen commented on Dec 9, 2013

    @mickhansen
    Contributor

    @jesslilly We can't really seem to find any resources indicating increased performance. And with the added complexity we won't attempt to support this.

    If you can provide resources for that document performance benefits for mysql/postgres we might revisit this.

  8. jesslilly commented on Dec 9, 2013

    @jesslilly
    Author

    Sure. Thanks for reviewing it.

  9. holm commented on Jul 20, 2016

    @holm
    Contributor

    Using prepared statements can make queries significantly faster, especially if the query is complex and returns few rows. This is because the prepared statement will be parsed and analyzed just once, which can be a big part of queries that are fast to execute and return little data.

  10. mickhansen commented on Jul 20, 2016

    @mickhansen
    Contributor

    @holm In cases where the connection is reused that is definitely true (which should be the case for most saturated pools).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions