Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
studyinhub opened this issue Jul 30, 2021 · 1 comment
Open

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

studyinhub opened this issue Jul 30, 2021 · 1 comment

Comments

@studyinhub
Copy link

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。

@lizheming
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants