@nuxodin/item 0.6.17 → 0.6.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxodin/item",
3
- "version": "0.6.17",
3
+ "version": "0.6.18",
4
4
  "description": "Reactive state library",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -5,7 +5,14 @@ import { schemaFromField } from './from-field.js'
5
5
 
6
6
  const dialect = {
7
7
  tables: async (query) => (await queryRows(query, 'SHOW TABLES')).map(r => Object.values(r)[0]),
8
- fields: async (query, table) => queryRows(query, `SHOW FULL FIELDS FROM ${quoteId(table)}`),
8
+ fields: async (query, table) => {
9
+ const rows = await queryRows(query, `SHOW FULL FIELDS FROM ${quoteId(table)}`)
10
+ // MariaDB's JSON is LONGTEXT with a json_valid() check: read back as text it would be altered on every run
11
+ const checks = await queryRows(query, `SELECT CHECK_CLAUSE FROM information_schema.CHECK_CONSTRAINTS
12
+ WHERE CONSTRAINT_SCHEMA = DATABASE() AND TABLE_NAME = '${String(table).replaceAll("'", "''")}'`).catch(() => [])
13
+ const json = new Set(checks.map(c => /^json_valid\(`(.+)`\)$/.exec(String(c.CHECK_CLAUSE))?.[1]))
14
+ return rows.map(r => json.has(r.Field) ? { ...r, Type: 'json' } : r)
15
+ },
9
16
  fromField: (row) => ({
10
17
  name: row.Field,
11
18
  prop: schemaFromField(row),