Skip to content

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

@studyinhub

Description

@studyinhub

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。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions