thinkjs icon indicating copy to clipboard operation
thinkjs copied to clipboard

think-model-mysql jsonFormat 不能去掉双引号

Open studyinhub opened this issue 4 years ago • 1 comments

const field = "name, JSON_EXTRACT(info, '$.age') AS age"; 在我这里这样写不行,必须是下面才行 const field = "name, JSON_EXTRACT(info, '$.age') AS info";

select(options, cache) { if (!this.config.jsonFormat) { return super.select(options, cache); }

return Promise.all([
  super.select(options, cache),
  this.schema.getSchema()
]).then(([data, schema]) => {
  const keys = Object.keys(schema).filter(key => schema[key].tinyType === 'json');
  (Array.isArray(data) ? data : [data]).forEach(row => {
    keys.filter(key => row[key] !== undefined).forEach(key => {
      row[key] = JSON.parse(row[key]);
    });
  });
  return data;
});

}

keys 返回的是 [info] 而 row 里返回的 age:{} keys.filter(key => row[key] !== undefined) row[info] 必然是 undefined。

studyinhub avatar Jul 30 '21 09:07 studyinhub

能否重新整理下内容,看不懂你在表达什么?

lizheming avatar Jul 30 '21 09:07 lizheming