jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
446 stars 63 forks source link

Pure SQL "words" not requiring any reference to the parameters block #9

Closed misner closed 5 years ago

misner commented 5 years ago

Hi Jeremy,

Have been using your wrapper for the past weeks, and it makes working with Aurora serverless a breeze (much easier than native use) ! thanks so much

However, I read the docs and the numerous examples, where you stress the fact some things must be "done" in a certain way (for example the ordering of the parameters), and i could not find a clear idea on the following issue:


EXAMPLE

let existing_author_from_db_query = await data.query(     
      `
        SELECT
          author_email,
          author_full_name,
          author_first_name,
          author_last_name
        FROM 
          results
        WHERE
          status = :status AND
          url_domain = :url_domain AND
          author_email IS NOT NULL AND
          author_full_name IS NOT NULL AND
          article_publication_date >= CURDATE() - INTERVAL 180 DAY
      `,
      {
        status: process.env.CONTEXT === "production" ? "prod" : "dev",         
        url_domain: article_domain,
      }          
    );

What would you recommend in terms of how to use your wrapper in such a case ?

Thanks so much for any help!

davegariepy commented 5 years ago

I think the pure SQL stuff is just that. If it’s a valid MySQL 5.6 keyword it should work.

For the passed parameters, from what I understand they need to be passed into the parameter object in the same order that they appear in the SQL query. If a parameter needs to be used twice I think that means it needs to be included in the passed parameter object twice, therefore maintaining the corresponding order to the SQL query. I haven’t actually tested that out though.

misner commented 5 years ago

Makes sense, thanks