记一次Sequelize中LEFT JOIN的使用_SQL

left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录  

   const sql = `
    SELECT
        post_candidate.*,
        post_info.*
    FROM
        post_candidate
    LEFT JOIN post_info 
        ON post_candidate.post_id = post_info.post_id
    WHERE 
      candidate_state = ${state} and candidate_id = ${this.jwtStrategy.payload.sub}
    `
    try {
      const data = (
        await sequelize.query(sql, {
          type: Sequelize.QueryTypes.SELECT, // 查询方式
          raw: true, // 是否使用数组组装的方式展示结果
          logging: true, // 是否将 SQL 语句打印到控制台
        })
      );
      return data;
    } catch (error) {
      return {
        code: 503,
        msg: `Service error: ${error}`,
      };
    }