Browse Source

feat: implement JSON_EXTRACT for mssql, mysql, pg

pull/9532/head
Verhille 2 months ago
parent
commit
cb77f071a0
  1. 11
      packages/nocodb/src/db/functionMappings/mssql.ts
  2. 11
      packages/nocodb/src/db/functionMappings/mysql.ts
  3. 13
      packages/nocodb/src/db/functionMappings/pg.ts

11
packages/nocodb/src/db/functionMappings/mssql.ts

@ -209,6 +209,17 @@ const mssql = {
),
};
},
JSON_EXTRACT: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return {
builder: knex.raw(
`CASE WHEN ISJSON(${
(await fn(pt.arguments[0])).builder
}) = 1 THEN JSON_VALUE(${(await fn(pt.arguments[0])).builder}, ${
(await fn(pt.arguments[1])).builder
}) ELSE NULL END${colAlias}`,
),
};
},
};
export default mssql;

11
packages/nocodb/src/db/functionMappings/mysql.ts

@ -171,6 +171,17 @@ END) ${colAlias}`,
),
};
},
JSON_EXTRACT: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return {
builder: knex.raw(
`CASE WHEN JSON_VALID(${
(await fn(pt.arguments[0])).builder
}) = 1 THEN JSON_EXTRACT(${(await fn(pt.arguments[0])).builder}, ${
(await fn(pt.arguments[1])).builder
}) ELSE NULL END${colAlias}`,
),
};
},
};
export default mysql2;

13
packages/nocodb/src/db/functionMappings/pg.ts

@ -359,6 +359,19 @@ END ${colAlias}`,
),
};
},
JSON_EXTRACT: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return {
builder: knex.raw(
`CASE WHEN (${
(await fn(pt.arguments[0])).builder
})::jsonb IS NOT NULL THEN (${
(await fn(pt.arguments[0])).builder
})::jsonb #> ${
(await fn(pt.arguments[1])).builder
} ELSE NULL END${colAlias}`,
),
};
},
};
export default pg;

Loading…
Cancel
Save