@nuxodin/item 0.6.16 → 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
|
@@ -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) =>
|
|
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),
|
|
@@ -102,6 +102,9 @@ export async function schemaToDb(schema, query, { force = false, patch = false }
|
|
|
102
102
|
const primaries = fields.filter(([, f]) => f['x-index'] === 'primary').map(([n]) => n)
|
|
103
103
|
|
|
104
104
|
if (!currTables.includes(table)) {
|
|
105
|
+
// Idea: WITHOUT ROWID when the primary key is not a single integer column and all other columns
|
|
106
|
+
// are narrow (numbers, booleans, short strings), e.g. measurement tables: about half the size.
|
|
107
|
+
// Requires NOT NULL key columns; only applies to newly created tables.
|
|
105
108
|
stmts.push(`CREATE TABLE ${quoteId(table)} (\n${createBody(table, fields, primaries)}\n);`)
|
|
106
109
|
stmts.push(...indexStatements(table, fields, primaries))
|
|
107
110
|
} else {
|