thinkjs / thinkjs/thinkjs

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

Open
#1,681 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.3k
Forks
614
PR merge metrics
No merged PRs in 30d

Description

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。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The affected entry point is the select(options, cache) method shown in the issue; reproduce it with JSON_EXTRACT(info, '$.age') AS age while JSON formatting is enabled. Trace how returned aliases are matched against the schema's JSON keys. Done means JSON values returned under an alias are parsed correctly rather than being skipped because the schema field name is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mysql
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.