This repo reproduces an issue with logging single INSERT and
UPDATE SQL queries. In Sequelize v5.21.5 parameters' values binded to a SQL query don't substitute tokens
prefixed with $ ($1, $2, $3, etc...) when logging the SQL query.
-
Clone the repo:
git clone [email protected]:ezze/sequelize-log-sql-issue
-
Install dependencies:
yarn
-
Configure database connection in
config/config.jsonfile. -
Create a database:
yarn db:create
-
Run a script to reproduce the issue:
yarn start
Expected (Sequelize v4) output:
Executing (...): START TRANSACTION;
Executing (...): INSERT INTO "task" ("id","created_at","updated_at","name","status") VALUES (DEFAULT,'2018-10-23 13:58:05.380 +00:00','2018-10-23 13:58:05.380 +00:00','First task',1) RETURNING *;
Executing (...): INSERT INTO "task" ("id","created_at","updated_at","name","status") VALUES (DEFAULT,'2018-10-23 13:58:05.387 +00:00','2018-10-23 13:58:05.387 +00:00','Second task',1),(DEFAULT,'2018-10-23 13:58:05.387 +00:00','2018-10-23 13:58:05.387 +00:00','Third task',0);
Executing (...): SELECT "id", "created_at" AS "createdAt", "updated_at" AS "updatedAt", "name", "status" FROM "task" AS "task" WHERE "task"."status" = 1;
Executing (...): UPDATE "task" SET "status"=2,"updated_at"='2018-10-23 13:58:05.398 +00:00' WHERE "status" = 1
Executing (...): COMMIT;
Given (Sequelize v5.21.5) output:
Executing (...): START TRANSACTION;
Executing (...): INSERT INTO "task" ("id","created_at","updated_at","name","status") VALUES (DEFAULT,$1,$2,$3,$4) RETURNING *;
Executing (...): INSERT INTO "task" ("id","created_at","updated_at","name","status") VALUES (DEFAULT,'2020-02-26 20:42:28.062 +00:00','2020-02-26 20:42:28.062 +00:00','Second task',1),(DEFAULT,'2020-02-26 20:42:28.062 +00:00','2020-02-26 20:42:28.062 +00:00','Third task',0) RETURNING *;
Executing (...): SELECT "id", "created_at" AS "createdAt", "updated_at" AS "updatedAt", "name", "status" FROM "task" AS "task" WHERE "task"."status" = 1;
Executing (...): UPDATE "task" SET "status"=$1,"updated_at"=$2 WHERE "status" = $3
Executing (...): COMMIT;