rake-db 2.8.7 → 2.8.8
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/index.d.ts +67 -66
- package/dist/index.js +22 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { columnTypes, quote, getRaw, EnumColumn, getColumnTypes, getTableData, ColumnType, resetTableData, UnknownColumn, TransactionAdapter, logParamToLogObject, createDb as createDb$1, Adapter, simplifyColumnDefault, columnsByType, instantiateColumn, DomainColumn, CustomTypeColumn, ArrayColumn, getConstraintKind, primaryKeyToCode, indexToCode, constraintToCode, TimestampTzColumn, referencesArgsToCode, constraintPropsToCode } from 'pqb';
|
|
2
|
-
import { getCallerFilePath, singleQuote, toSnakeCase, isRaw, toArray, snakeCaseKey,
|
|
2
|
+
import { getCallerFilePath, singleQuote, toSnakeCase, isRaw, toArray, snakeCaseKey, emptyObject, consumeColumnName, deepCompare, raw, pathToLog, emptyArray, getImportPath, toCamelCase, codeToString, addCode, rawToCode, quoteObjectKey, backtickQuote } from 'orchid-core';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { readdir, mkdir, writeFile } from 'fs/promises';
|
|
5
5
|
import prompts from 'prompts';
|
|
@@ -505,7 +505,7 @@ const primaryKeyToSql = (primaryKey) => {
|
|
|
505
505
|
|
|
506
506
|
const tableMethods = {
|
|
507
507
|
enum(name) {
|
|
508
|
-
return new EnumColumn(
|
|
508
|
+
return new EnumColumn(name, []);
|
|
509
509
|
}
|
|
510
510
|
};
|
|
511
511
|
|
|
@@ -753,7 +753,7 @@ const mergeTableData = (a, b) => {
|
|
|
753
753
|
};
|
|
754
754
|
function add(item, options) {
|
|
755
755
|
if (item instanceof ColumnType) {
|
|
756
|
-
return addOrDrop(
|
|
756
|
+
return addOrDrop("add", item, options);
|
|
757
757
|
} else if (item === emptyObject) {
|
|
758
758
|
mergeTableData(changeTableData.add, getTableData());
|
|
759
759
|
resetTableData();
|
|
@@ -772,7 +772,7 @@ function add(item, options) {
|
|
|
772
772
|
}
|
|
773
773
|
const drop = function(item, options) {
|
|
774
774
|
if (item instanceof ColumnType) {
|
|
775
|
-
return addOrDrop(
|
|
775
|
+
return addOrDrop("drop", item, options);
|
|
776
776
|
} else if (item === emptyObject) {
|
|
777
777
|
mergeTableData(changeTableData.drop, getTableData());
|
|
778
778
|
resetTableData();
|
|
@@ -789,9 +789,10 @@ const drop = function(item, options) {
|
|
|
789
789
|
return result;
|
|
790
790
|
}
|
|
791
791
|
};
|
|
792
|
-
const addOrDrop = (
|
|
793
|
-
|
|
794
|
-
|
|
792
|
+
const addOrDrop = (type, item, options) => {
|
|
793
|
+
const name = consumeColumnName();
|
|
794
|
+
if (name) {
|
|
795
|
+
item.data.name = name;
|
|
795
796
|
}
|
|
796
797
|
if (item instanceof UnknownColumn) {
|
|
797
798
|
const empty = columnTypeToColumnChange({
|
|
@@ -835,7 +836,13 @@ const columnTypeToColumnChange = (item) => {
|
|
|
835
836
|
}
|
|
836
837
|
return item.to;
|
|
837
838
|
};
|
|
839
|
+
const nameKey = Symbol("name");
|
|
838
840
|
const tableChangeMethods = __spreadProps$2(__spreadValues$3({}, tableMethods), {
|
|
841
|
+
name(name) {
|
|
842
|
+
const types = Object.create(columnTypes.name.call(this, name));
|
|
843
|
+
types[nameKey] = name;
|
|
844
|
+
return types;
|
|
845
|
+
},
|
|
839
846
|
add,
|
|
840
847
|
drop,
|
|
841
848
|
change(from, to, options) {
|
|
@@ -2496,22 +2503,22 @@ const getColumn = (ctx, data, domains, _a) => {
|
|
|
2496
2503
|
} else {
|
|
2497
2504
|
const domainColumn = domains[`${typeSchema}.${type}`];
|
|
2498
2505
|
if (domainColumn) {
|
|
2499
|
-
column = new DomainColumn(
|
|
2506
|
+
column = new DomainColumn(type).as(domainColumn);
|
|
2500
2507
|
} else {
|
|
2501
2508
|
const enumType = data.enums.find(
|
|
2502
2509
|
(item) => item.name === type && item.schemaName === typeSchema
|
|
2503
2510
|
);
|
|
2504
2511
|
if (enumType) {
|
|
2505
|
-
column = new EnumColumn(
|
|
2512
|
+
column = new EnumColumn(type, enumType.values);
|
|
2506
2513
|
} else {
|
|
2507
|
-
column = new CustomTypeColumn(
|
|
2514
|
+
column = new CustomTypeColumn(type);
|
|
2508
2515
|
((_b2 = (_a2 = ctx.unsupportedTypes)[type]) != null ? _b2 : _a2[type] = []).push(
|
|
2509
2516
|
`${schemaName}${tableName ? `.${tableName}` : ""}.${name}`
|
|
2510
2517
|
);
|
|
2511
2518
|
}
|
|
2512
2519
|
}
|
|
2513
2520
|
}
|
|
2514
|
-
return isArray ? new ArrayColumn(
|
|
2521
|
+
return isArray ? new ArrayColumn(column) : column;
|
|
2515
2522
|
};
|
|
2516
2523
|
const getColumnType = (type, isSerial) => {
|
|
2517
2524
|
if (!isSerial)
|
|
@@ -2751,9 +2758,10 @@ const makeColumnsShape = (ctx, data, domains, tableName, columns, primaryKey, in
|
|
|
2751
2758
|
const camelCaseName = toCamelCase(item.name);
|
|
2752
2759
|
if (ctx.snakeCase) {
|
|
2753
2760
|
const snakeCaseName = toSnakeCase(camelCaseName);
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2761
|
+
if (snakeCaseName !== item.name)
|
|
2762
|
+
column.data.name = item.name;
|
|
2763
|
+
} else if (camelCaseName !== item.name) {
|
|
2764
|
+
column.data.name = item.name;
|
|
2757
2765
|
}
|
|
2758
2766
|
shape[camelCaseName] = column;
|
|
2759
2767
|
}
|