amir
amir

Reputation: 2573

get records after creation using sequelize raw query

I am using sequelize for migration. here I execute an INSERT query with following options but its didnot return created records:

const res = oldUsers.map(u => sequelize.query(
        `INSERT INTO ${LP_LOCATIONS_TABLE} (name, address, city) 
          VALUES (
         '${u.email}', '${u.address}', '${u.city}');`,
        { type: DataTypes.QueryTypes.INSERT, raw: true },
      ))

the output is an array of array like below:

[ [[0],[1]] ] 

i expect to get created recorders. specially PK. how can I fix it?

Upvotes: 0

Views: 1431

Answers (2)

amir
amir

Reputation: 2573

I forgot to put RETURNING * at the end of the raw SQL query.

Upvotes: 1

KenOn10
KenOn10

Reputation: 1968

From the doc, you may have to specify the option returning:true to make this happen. I use mySql, so can't test (the returning option is only for postgres).

Upvotes: 0

Related Questions