jeremydaly / data-api-client

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

Handling multiple statements #107

Closed cacowen closed 2 years ago

cacowen commented 2 years ago

One of the uses of this package is to handle db migrations. Sometimes a migration might need to have more than one statement. The migrations are created as a .sql file, then when ran the code reads in the sql file and does a db.query(sqlFileContents). Most of the time this works as the sql file is just a single statement, however, I often have migrations that need more than that. My work around so far is just to split up all the statements. My problem now is creating stored procs.

DELIMITER //
CREATE PROCEDURE `new_proc`
...
DELIMITER ;

How do I handle setting the DELIMITER when only 1 statement is allowed?

My thinking is to do something like:

db.transaction()
  .query('DELIMITER //')
  .query(sqlStatement)
  .query(DELIMITER ;)
  .commit();

But if there is a way to do this all in one or if there is some setting to allow multiple statements (despite security reasons) I would love to know. Thank you.

cacowen commented 2 years ago

Turns out the DELIMITER change is not needed and the db.query(sqlFileContents) will work without it. I will just update the scripts and continue on. Thanks.