relq 1.0.84 → 1.0.85
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/dist/cjs/cli/utils/schema-to-ast.cjs +1 -1
- package/dist/cjs/core/shared/column-mapping.cjs +1 -1
- package/dist/cjs/core/shared/transform.cjs +6 -2
- package/dist/cjs/schema-definition/pg-schema/column-types/column-builder.cjs +5 -5
- package/dist/cjs/schema-definition/pg-schema/column-types/custom-types.cjs +2 -2
- package/dist/cjs/schema-definition/pg-schema/column-types/domain-types.cjs +4 -4
- package/dist/cjs/schema-definition/pg-schema/pg-enum.cjs +3 -1
- package/dist/cjs/schema-definition/pg-schema/schema-builder.cjs +1 -1
- package/dist/cjs/schema-definition/pg-schema/table-definition/sql-generation.cjs +1 -1
- package/dist/cjs/schema-definition/pg-schema/validate-schema/validators.cjs +1 -1
- package/dist/cjs/schema-definition/sqlite-schema/table-definition/ast-generation.cjs +1 -1
- package/dist/cjs/schema-definition/sqlite-schema/table-definition/sql-generation.cjs +1 -1
- package/dist/cjs/schema-definition/sqlite-schema/table-definition/table-core.cjs +1 -1
- package/dist/cjs/utils/type-coercion.cjs +4 -2
- package/dist/esm/cli/utils/schema-to-ast.js +1 -1
- package/dist/esm/core/shared/column-mapping.js +1 -1
- package/dist/esm/core/shared/transform.js +6 -2
- package/dist/esm/schema-definition/pg-schema/column-types/column-builder.js +5 -5
- package/dist/esm/schema-definition/pg-schema/column-types/custom-types.js +2 -2
- package/dist/esm/schema-definition/pg-schema/column-types/domain-types.js +4 -4
- package/dist/esm/schema-definition/pg-schema/pg-enum.js +3 -1
- package/dist/esm/schema-definition/pg-schema/schema-builder.js +1 -1
- package/dist/esm/schema-definition/pg-schema/table-definition/sql-generation.js +1 -1
- package/dist/esm/schema-definition/pg-schema/validate-schema/validators.js +1 -1
- package/dist/esm/schema-definition/sqlite-schema/table-definition/ast-generation.js +1 -1
- package/dist/esm/schema-definition/sqlite-schema/table-definition/sql-generation.js +1 -1
- package/dist/esm/schema-definition/sqlite-schema/table-definition/table-core.js +1 -1
- package/dist/esm/utils/type-coercion.js +4 -2
- package/package.json +1 -1
|
@@ -538,7 +538,7 @@ function compositeToAST(composite) {
|
|
|
538
538
|
const config = fieldDef.$config || fieldDef;
|
|
539
539
|
attributes.push({
|
|
540
540
|
name: fieldName,
|
|
541
|
-
type: config.$type || 'text',
|
|
541
|
+
type: config.$sqlType || (typeof config.$type === 'string' ? config.$type : null) || 'text',
|
|
542
542
|
collation: config.$collation,
|
|
543
543
|
});
|
|
544
544
|
}
|
|
@@ -24,7 +24,7 @@ function buildColumnMappings(schema, mappings, debugLog) {
|
|
|
24
24
|
const propToFields = new Map();
|
|
25
25
|
for (const [propName, colDef] of Object.entries(columns)) {
|
|
26
26
|
const dbColName = colDef?.$columnName ?? propName;
|
|
27
|
-
const colType = colDef?.$type
|
|
27
|
+
const colType = colDef?.$sqlType || (typeof colDef?.$type === 'string' ? colDef.$type : undefined) || 'TEXT';
|
|
28
28
|
propToDb.set(propName, dbColName);
|
|
29
29
|
dbToProp.set(dbColName, propName);
|
|
30
30
|
propToType.set(propName, colType);
|
|
@@ -23,8 +23,12 @@ function buildColumnTypeMap(tableDef) {
|
|
|
23
23
|
const typeMap = new Map();
|
|
24
24
|
const columns = tableDef.$columns || tableDef;
|
|
25
25
|
for (const [key, colDef] of Object.entries(columns)) {
|
|
26
|
-
if (colDef && typeof colDef === 'object'
|
|
27
|
-
|
|
26
|
+
if (colDef && typeof colDef === 'object') {
|
|
27
|
+
const col = colDef;
|
|
28
|
+
const sqlType = col.$sqlType || (typeof col.$type === 'string' ? col.$type : undefined);
|
|
29
|
+
if (sqlType) {
|
|
30
|
+
typeMap.set(key, sqlType);
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
return typeMap;
|
|
@@ -151,7 +151,7 @@ function createColumn(type) {
|
|
|
151
151
|
config.$length = len;
|
|
152
152
|
const baseType = config.$type.replace(/\(\d+\)/, '');
|
|
153
153
|
config.$type = `${baseType}(${len})`;
|
|
154
|
-
return Object.assign(this, { $length: len, $type: config.$type });
|
|
154
|
+
return Object.assign(this, { $length: len, $type: config.$type, $sqlType: config.$type });
|
|
155
155
|
},
|
|
156
156
|
precision(p) {
|
|
157
157
|
config.$precision = p;
|
|
@@ -159,7 +159,7 @@ function createColumn(type) {
|
|
|
159
159
|
config.$type = config.$scale !== undefined
|
|
160
160
|
? `${base}(${p}, ${config.$scale})`
|
|
161
161
|
: `${base}(${p})`;
|
|
162
|
-
return Object.assign(this, { $precision: p, $type: config.$type });
|
|
162
|
+
return Object.assign(this, { $precision: p, $type: config.$type, $sqlType: config.$type });
|
|
163
163
|
},
|
|
164
164
|
scale(s) {
|
|
165
165
|
config.$scale = s;
|
|
@@ -167,7 +167,7 @@ function createColumn(type) {
|
|
|
167
167
|
config.$type = config.$precision !== undefined
|
|
168
168
|
? `${base}(${config.$precision}, ${s})`
|
|
169
169
|
: `${base}(38, ${s})`;
|
|
170
|
-
return Object.assign(this, { $scale: s, $type: config.$type });
|
|
170
|
+
return Object.assign(this, { $scale: s, $type: config.$type, $sqlType: config.$type });
|
|
171
171
|
},
|
|
172
172
|
withTimezone() {
|
|
173
173
|
config.$withTimezone = true;
|
|
@@ -177,12 +177,12 @@ function createColumn(type) {
|
|
|
177
177
|
else if (config.$type === 'TIME') {
|
|
178
178
|
config.$type = 'TIMETZ';
|
|
179
179
|
}
|
|
180
|
-
return Object.assign(this, { $withTimezone: true, $type: config.$type });
|
|
180
|
+
return Object.assign(this, { $withTimezone: true, $type: config.$type, $sqlType: config.$type });
|
|
181
181
|
},
|
|
182
182
|
dimensions(d) {
|
|
183
183
|
config.$dimensions = d;
|
|
184
184
|
config.$type = `VECTOR(${d})`;
|
|
185
|
-
return Object.assign(this, { $dimensions: d, $type: config.$type });
|
|
185
|
+
return Object.assign(this, { $dimensions: d, $type: config.$type, $sqlType: config.$type });
|
|
186
186
|
},
|
|
187
187
|
comment(text) {
|
|
188
188
|
config.$comment = text;
|
|
@@ -15,7 +15,7 @@ function pgComposite(name, fields) {
|
|
|
15
15
|
const config = fieldConfig;
|
|
16
16
|
return {
|
|
17
17
|
name: fieldName,
|
|
18
|
-
type: config.$type,
|
|
18
|
+
type: config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'TEXT'),
|
|
19
19
|
collation: undefined,
|
|
20
20
|
};
|
|
21
21
|
});
|
|
@@ -43,7 +43,7 @@ function generateCompositeTypeSQL(composite) {
|
|
|
43
43
|
const fieldDefs = [];
|
|
44
44
|
for (const [fieldName, fieldConfig] of Object.entries(composite.$fields)) {
|
|
45
45
|
const config = fieldConfig;
|
|
46
|
-
let fieldDef = `"${fieldName}" ${config.$type}`;
|
|
46
|
+
let fieldDef = `"${fieldName}" ${config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'TEXT')}`;
|
|
47
47
|
if (config.$nullable === false) {
|
|
48
48
|
fieldDef += ' NOT NULL';
|
|
49
49
|
}
|
|
@@ -139,8 +139,8 @@ function createDomainValueExpr() {
|
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
function pgDomain(name, baseType, checks) {
|
|
142
|
-
const
|
|
143
|
-
const baseTypeStr =
|
|
142
|
+
const bt = baseType;
|
|
143
|
+
const baseTypeStr = bt.$sqlType || (typeof bt.$type === 'string' ? bt.$type : null) || 'TEXT';
|
|
144
144
|
const constraints = [];
|
|
145
145
|
let validateFn;
|
|
146
146
|
if (checks) {
|
|
@@ -163,8 +163,8 @@ function pgDomain(name, baseType, checks) {
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
const notNull =
|
|
167
|
-
const defaultValue =
|
|
166
|
+
const notNull = bt?.$nullable === false;
|
|
167
|
+
const defaultValue = bt?.$default;
|
|
168
168
|
const domainFn = (columnName) => {
|
|
169
169
|
const col = (0, column_builder_1.createColumnWithName)(name, columnName);
|
|
170
170
|
if (validateFn) {
|
|
@@ -8,6 +8,7 @@ function pgEnum(name, values) {
|
|
|
8
8
|
const config = function (columnName) {
|
|
9
9
|
const col = {
|
|
10
10
|
$type: name,
|
|
11
|
+
$sqlType: name,
|
|
11
12
|
$enumName: name,
|
|
12
13
|
$checkValues: values,
|
|
13
14
|
};
|
|
@@ -38,7 +39,8 @@ function pgEnum(name, values) {
|
|
|
38
39
|
array() {
|
|
39
40
|
col.$array = true;
|
|
40
41
|
col.$type = `${name}[]`;
|
|
41
|
-
|
|
42
|
+
col.$sqlType = `${name}[]`;
|
|
43
|
+
return Object.assign(this, { $array: true, $type: `${name}[]`, $sqlType: `${name}[]` });
|
|
42
44
|
},
|
|
43
45
|
$id(trackingId) {
|
|
44
46
|
col.$trackingId = trackingId;
|
|
@@ -21,7 +21,7 @@ function createTableProxy(name, columns, tableDef) {
|
|
|
21
21
|
for (const [colKey, colDef] of Object.entries(columns)) {
|
|
22
22
|
const config = colDef.$config || colDef;
|
|
23
23
|
const sqlName = config.$sqlName || config.$columnName || colKey;
|
|
24
|
-
const colType = config.$sqlType || config.$type || 'unknown';
|
|
24
|
+
const colType = config.$sqlType || (typeof config.$type === 'string' ? config.$type : undefined) || 'unknown';
|
|
25
25
|
proxy[colKey] = {
|
|
26
26
|
$table: name,
|
|
27
27
|
$column: sqlName,
|
|
@@ -116,7 +116,7 @@ function generateCreateTableSQL(def) {
|
|
|
116
116
|
function generateColumnSQL(name, config) {
|
|
117
117
|
const actualName = config.$columnName || name;
|
|
118
118
|
const parts = [pg_format_1.default.ident(actualName)];
|
|
119
|
-
let typeName = config.$type;
|
|
119
|
+
let typeName = config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'TEXT');
|
|
120
120
|
if (config.$array) {
|
|
121
121
|
const dims = config.$dimensions ?? 1;
|
|
122
122
|
typeName += '[]'.repeat(dims);
|
|
@@ -76,7 +76,7 @@ function validateTable(table, tableName, features, errors, warnings, info, allow
|
|
|
76
76
|
validateTableFeatures(table, tableName, features, errors, warnings);
|
|
77
77
|
}
|
|
78
78
|
function validateColumn(column, location, features, errors, warnings, allowedCustomTypes) {
|
|
79
|
-
const colType = column.$
|
|
79
|
+
const colType = column.$sqlType || (typeof column.$type === 'string' ? column.$type : undefined) || 'unknown';
|
|
80
80
|
if (allowedCustomTypes.includes(colType.toUpperCase())) {
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
@@ -17,7 +17,7 @@ function extractDefaultValue(col) {
|
|
|
17
17
|
return undefined;
|
|
18
18
|
}
|
|
19
19
|
function resolveColumnType(col) {
|
|
20
|
-
const base = col.$sqlType || col.$type || 'TEXT';
|
|
20
|
+
const base = col.$sqlType || (typeof col.$type === 'string' ? col.$type : null) || 'TEXT';
|
|
21
21
|
if (col.$length !== undefined) {
|
|
22
22
|
return `${base}(${col.$length})`;
|
|
23
23
|
}
|
|
@@ -32,7 +32,7 @@ function formatDefault(col) {
|
|
|
32
32
|
}
|
|
33
33
|
function generateColumnSQL(name, col) {
|
|
34
34
|
const parts = [quoteSQLiteIdentifier(col.$columnName || name)];
|
|
35
|
-
parts.push(col.$type || 'TEXT');
|
|
35
|
+
parts.push(col.$sqlType || (typeof col.$type === 'string' ? col.$type : null) || 'TEXT');
|
|
36
36
|
if (col.$primaryKey) {
|
|
37
37
|
parts.push('PRIMARY KEY');
|
|
38
38
|
if (col.$autoincrement) {
|
|
@@ -14,7 +14,7 @@ function sqliteTable(name, columns, options) {
|
|
|
14
14
|
for (const [colName, colConfig] of Object.entries(columns)) {
|
|
15
15
|
const col = colConfig;
|
|
16
16
|
if (col.$autoincrement) {
|
|
17
|
-
const sqlType = (col.$sqlType || col.$type || '').toUpperCase();
|
|
17
|
+
const sqlType = (col.$sqlType || (typeof col.$type === 'string' ? col.$type : '') || '').toUpperCase();
|
|
18
18
|
if (sqlType !== 'INTEGER' || !col.$primaryKey) {
|
|
19
19
|
throw new Error(`[sqliteTable] AUTOINCREMENT on column "${colName}" in table "${name}" ` +
|
|
20
20
|
`requires INTEGER PRIMARY KEY. Got type "${sqlType}", primaryKey=${col.$primaryKey}.`);
|
|
@@ -56,7 +56,8 @@ function deserializeRow(row, schema) {
|
|
|
56
56
|
const columnMap = new Map();
|
|
57
57
|
for (const [key, config] of Object.entries(schema)) {
|
|
58
58
|
const dbColumnName = config.$columnName || key;
|
|
59
|
-
|
|
59
|
+
const sqlType = config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'TEXT');
|
|
60
|
+
columnMap.set(dbColumnName, { key, type: sqlType });
|
|
60
61
|
}
|
|
61
62
|
for (const [dbColumn, value] of Object.entries(row)) {
|
|
62
63
|
const mapping = columnMap.get(dbColumn);
|
|
@@ -102,7 +103,8 @@ function serializeRow(row, schema) {
|
|
|
102
103
|
for (const [key, value] of Object.entries(row)) {
|
|
103
104
|
const config = schema[key];
|
|
104
105
|
if (config) {
|
|
105
|
-
|
|
106
|
+
const sqlType = config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'TEXT');
|
|
107
|
+
result[key] = serializeValue(value, sqlType);
|
|
106
108
|
}
|
|
107
109
|
else {
|
|
108
110
|
result[key] = value;
|
|
@@ -504,7 +504,7 @@ export function compositeToAST(composite) {
|
|
|
504
504
|
const config = fieldDef.$config || fieldDef;
|
|
505
505
|
attributes.push({
|
|
506
506
|
name: fieldName,
|
|
507
|
-
type: config.$type || 'text',
|
|
507
|
+
type: config.$sqlType || (typeof config.$type === 'string' ? config.$type : null) || 'text',
|
|
508
508
|
collation: config.$collation,
|
|
509
509
|
});
|
|
510
510
|
}
|
|
@@ -17,7 +17,7 @@ export function buildColumnMappings(schema, mappings, debugLog) {
|
|
|
17
17
|
const propToFields = new Map();
|
|
18
18
|
for (const [propName, colDef] of Object.entries(columns)) {
|
|
19
19
|
const dbColName = colDef?.$columnName ?? propName;
|
|
20
|
-
const colType = colDef?.$type
|
|
20
|
+
const colType = colDef?.$sqlType || (typeof colDef?.$type === 'string' ? colDef.$type : undefined) || 'TEXT';
|
|
21
21
|
propToDb.set(propName, dbColName);
|
|
22
22
|
dbToProp.set(dbColName, propName);
|
|
23
23
|
propToType.set(propName, colType);
|
|
@@ -18,8 +18,12 @@ export function buildColumnTypeMap(tableDef) {
|
|
|
18
18
|
const typeMap = new Map();
|
|
19
19
|
const columns = tableDef.$columns || tableDef;
|
|
20
20
|
for (const [key, colDef] of Object.entries(columns)) {
|
|
21
|
-
if (colDef && typeof colDef === 'object'
|
|
22
|
-
|
|
21
|
+
if (colDef && typeof colDef === 'object') {
|
|
22
|
+
const col = colDef;
|
|
23
|
+
const sqlType = col.$sqlType || (typeof col.$type === 'string' ? col.$type : undefined);
|
|
24
|
+
if (sqlType) {
|
|
25
|
+
typeMap.set(key, sqlType);
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
return typeMap;
|
|
@@ -146,7 +146,7 @@ export function createColumn(type) {
|
|
|
146
146
|
config.$length = len;
|
|
147
147
|
const baseType = config.$type.replace(/\(\d+\)/, '');
|
|
148
148
|
config.$type = `${baseType}(${len})`;
|
|
149
|
-
return Object.assign(this, { $length: len, $type: config.$type });
|
|
149
|
+
return Object.assign(this, { $length: len, $type: config.$type, $sqlType: config.$type });
|
|
150
150
|
},
|
|
151
151
|
precision(p) {
|
|
152
152
|
config.$precision = p;
|
|
@@ -154,7 +154,7 @@ export function createColumn(type) {
|
|
|
154
154
|
config.$type = config.$scale !== undefined
|
|
155
155
|
? `${base}(${p}, ${config.$scale})`
|
|
156
156
|
: `${base}(${p})`;
|
|
157
|
-
return Object.assign(this, { $precision: p, $type: config.$type });
|
|
157
|
+
return Object.assign(this, { $precision: p, $type: config.$type, $sqlType: config.$type });
|
|
158
158
|
},
|
|
159
159
|
scale(s) {
|
|
160
160
|
config.$scale = s;
|
|
@@ -162,7 +162,7 @@ export function createColumn(type) {
|
|
|
162
162
|
config.$type = config.$precision !== undefined
|
|
163
163
|
? `${base}(${config.$precision}, ${s})`
|
|
164
164
|
: `${base}(38, ${s})`;
|
|
165
|
-
return Object.assign(this, { $scale: s, $type: config.$type });
|
|
165
|
+
return Object.assign(this, { $scale: s, $type: config.$type, $sqlType: config.$type });
|
|
166
166
|
},
|
|
167
167
|
withTimezone() {
|
|
168
168
|
config.$withTimezone = true;
|
|
@@ -172,12 +172,12 @@ export function createColumn(type) {
|
|
|
172
172
|
else if (config.$type === 'TIME') {
|
|
173
173
|
config.$type = 'TIMETZ';
|
|
174
174
|
}
|
|
175
|
-
return Object.assign(this, { $withTimezone: true, $type: config.$type });
|
|
175
|
+
return Object.assign(this, { $withTimezone: true, $type: config.$type, $sqlType: config.$type });
|
|
176
176
|
},
|
|
177
177
|
dimensions(d) {
|
|
178
178
|
config.$dimensions = d;
|
|
179
179
|
config.$type = `VECTOR(${d})`;
|
|
180
|
-
return Object.assign(this, { $dimensions: d, $type: config.$type });
|
|
180
|
+
return Object.assign(this, { $dimensions: d, $type: config.$type, $sqlType: config.$type });
|
|
181
181
|
},
|
|
182
182
|
comment(text) {
|
|
183
183
|
config.$comment = text;
|
|
@@ -9,7 +9,7 @@ export function pgComposite(name, fields) {
|
|
|
9
9
|
const config = fieldConfig;
|
|
10
10
|
return {
|
|
11
11
|
name: fieldName,
|
|
12
|
-
type: config.$type,
|
|
12
|
+
type: config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'TEXT'),
|
|
13
13
|
collation: undefined,
|
|
14
14
|
};
|
|
15
15
|
});
|
|
@@ -37,7 +37,7 @@ export function generateCompositeTypeSQL(composite) {
|
|
|
37
37
|
const fieldDefs = [];
|
|
38
38
|
for (const [fieldName, fieldConfig] of Object.entries(composite.$fields)) {
|
|
39
39
|
const config = fieldConfig;
|
|
40
|
-
let fieldDef = `"${fieldName}" ${config.$type}`;
|
|
40
|
+
let fieldDef = `"${fieldName}" ${config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'TEXT')}`;
|
|
41
41
|
if (config.$nullable === false) {
|
|
42
42
|
fieldDef += ' NOT NULL';
|
|
43
43
|
}
|
|
@@ -135,8 +135,8 @@ function createDomainValueExpr() {
|
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
export function pgDomain(name, baseType, checks) {
|
|
138
|
-
const
|
|
139
|
-
const baseTypeStr =
|
|
138
|
+
const bt = baseType;
|
|
139
|
+
const baseTypeStr = bt.$sqlType || (typeof bt.$type === 'string' ? bt.$type : null) || 'TEXT';
|
|
140
140
|
const constraints = [];
|
|
141
141
|
let validateFn;
|
|
142
142
|
if (checks) {
|
|
@@ -159,8 +159,8 @@ export function pgDomain(name, baseType, checks) {
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
const notNull =
|
|
163
|
-
const defaultValue =
|
|
162
|
+
const notNull = bt?.$nullable === false;
|
|
163
|
+
const defaultValue = bt?.$default;
|
|
164
164
|
const domainFn = (columnName) => {
|
|
165
165
|
const col = createColumnWithName(name, columnName);
|
|
166
166
|
if (validateFn) {
|
|
@@ -2,6 +2,7 @@ export function pgEnum(name, values) {
|
|
|
2
2
|
const config = function (columnName) {
|
|
3
3
|
const col = {
|
|
4
4
|
$type: name,
|
|
5
|
+
$sqlType: name,
|
|
5
6
|
$enumName: name,
|
|
6
7
|
$checkValues: values,
|
|
7
8
|
};
|
|
@@ -32,7 +33,8 @@ export function pgEnum(name, values) {
|
|
|
32
33
|
array() {
|
|
33
34
|
col.$array = true;
|
|
34
35
|
col.$type = `${name}[]`;
|
|
35
|
-
|
|
36
|
+
col.$sqlType = `${name}[]`;
|
|
37
|
+
return Object.assign(this, { $array: true, $type: `${name}[]`, $sqlType: `${name}[]` });
|
|
36
38
|
},
|
|
37
39
|
$id(trackingId) {
|
|
38
40
|
col.$trackingId = trackingId;
|
|
@@ -17,7 +17,7 @@ function createTableProxy(name, columns, tableDef) {
|
|
|
17
17
|
for (const [colKey, colDef] of Object.entries(columns)) {
|
|
18
18
|
const config = colDef.$config || colDef;
|
|
19
19
|
const sqlName = config.$sqlName || config.$columnName || colKey;
|
|
20
|
-
const colType = config.$sqlType || config.$type || 'unknown';
|
|
20
|
+
const colType = config.$sqlType || (typeof config.$type === 'string' ? config.$type : undefined) || 'unknown';
|
|
21
21
|
proxy[colKey] = {
|
|
22
22
|
$table: name,
|
|
23
23
|
$column: sqlName,
|
|
@@ -105,7 +105,7 @@ export function generateCreateTableSQL(def) {
|
|
|
105
105
|
export function generateColumnSQL(name, config) {
|
|
106
106
|
const actualName = config.$columnName || name;
|
|
107
107
|
const parts = [format.ident(actualName)];
|
|
108
|
-
let typeName = config.$type;
|
|
108
|
+
let typeName = config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'TEXT');
|
|
109
109
|
if (config.$array) {
|
|
110
110
|
const dims = config.$dimensions ?? 1;
|
|
111
111
|
typeName += '[]'.repeat(dims);
|
|
@@ -73,7 +73,7 @@ function validateTable(table, tableName, features, errors, warnings, info, allow
|
|
|
73
73
|
validateTableFeatures(table, tableName, features, errors, warnings);
|
|
74
74
|
}
|
|
75
75
|
function validateColumn(column, location, features, errors, warnings, allowedCustomTypes) {
|
|
76
|
-
const colType = column.$
|
|
76
|
+
const colType = column.$sqlType || (typeof column.$type === 'string' ? column.$type : undefined) || 'unknown';
|
|
77
77
|
if (allowedCustomTypes.includes(colType.toUpperCase())) {
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
@@ -14,7 +14,7 @@ function extractDefaultValue(col) {
|
|
|
14
14
|
return undefined;
|
|
15
15
|
}
|
|
16
16
|
function resolveColumnType(col) {
|
|
17
|
-
const base = col.$sqlType || col.$type || 'TEXT';
|
|
17
|
+
const base = col.$sqlType || (typeof col.$type === 'string' ? col.$type : null) || 'TEXT';
|
|
18
18
|
if (col.$length !== undefined) {
|
|
19
19
|
return `${base}(${col.$length})`;
|
|
20
20
|
}
|
|
@@ -27,7 +27,7 @@ function formatDefault(col) {
|
|
|
27
27
|
}
|
|
28
28
|
function generateColumnSQL(name, col) {
|
|
29
29
|
const parts = [quoteSQLiteIdentifier(col.$columnName || name)];
|
|
30
|
-
parts.push(col.$type || 'TEXT');
|
|
30
|
+
parts.push(col.$sqlType || (typeof col.$type === 'string' ? col.$type : null) || 'TEXT');
|
|
31
31
|
if (col.$primaryKey) {
|
|
32
32
|
parts.push('PRIMARY KEY');
|
|
33
33
|
if (col.$autoincrement) {
|
|
@@ -11,7 +11,7 @@ export function sqliteTable(name, columns, options) {
|
|
|
11
11
|
for (const [colName, colConfig] of Object.entries(columns)) {
|
|
12
12
|
const col = colConfig;
|
|
13
13
|
if (col.$autoincrement) {
|
|
14
|
-
const sqlType = (col.$sqlType || col.$type || '').toUpperCase();
|
|
14
|
+
const sqlType = (col.$sqlType || (typeof col.$type === 'string' ? col.$type : '') || '').toUpperCase();
|
|
15
15
|
if (sqlType !== 'INTEGER' || !col.$primaryKey) {
|
|
16
16
|
throw new Error(`[sqliteTable] AUTOINCREMENT on column "${colName}" in table "${name}" ` +
|
|
17
17
|
`requires INTEGER PRIMARY KEY. Got type "${sqlType}", primaryKey=${col.$primaryKey}.`);
|
|
@@ -48,7 +48,8 @@ export function deserializeRow(row, schema) {
|
|
|
48
48
|
const columnMap = new Map();
|
|
49
49
|
for (const [key, config] of Object.entries(schema)) {
|
|
50
50
|
const dbColumnName = config.$columnName || key;
|
|
51
|
-
|
|
51
|
+
const sqlType = config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'TEXT');
|
|
52
|
+
columnMap.set(dbColumnName, { key, type: sqlType });
|
|
52
53
|
}
|
|
53
54
|
for (const [dbColumn, value] of Object.entries(row)) {
|
|
54
55
|
const mapping = columnMap.get(dbColumn);
|
|
@@ -94,7 +95,8 @@ export function serializeRow(row, schema) {
|
|
|
94
95
|
for (const [key, value] of Object.entries(row)) {
|
|
95
96
|
const config = schema[key];
|
|
96
97
|
if (config) {
|
|
97
|
-
|
|
98
|
+
const sqlType = config.$sqlType || (typeof config.$type === 'string' ? config.$type : 'TEXT');
|
|
99
|
+
result[key] = serializeValue(value, sqlType);
|
|
98
100
|
}
|
|
99
101
|
else {
|
|
100
102
|
result[key] = value;
|