orchid-orm 1.4.22 → 1.5.0
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/CHANGELOG.md +13 -0
- package/dist/index.esm.js +36 -20
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +35 -19
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/codegen/updateTableFile/changeTable.test.ts +166 -10
- package/src/codegen/updateTableFile/changeTable.ts +44 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# orchid-orm
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Change index options: column or expression is required, operator renamed to opclass
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- f1cd5db: Handle multiple indexes and foreignKeys of the column
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- Updated dependencies [f1cd5db]
|
|
14
|
+
- pqb@0.9.0
|
|
15
|
+
|
|
3
16
|
## 1.4.22
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getColumnTypes, addQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, getQueryAs, toSqlCacheKey, NotFoundError, relationQueryKey, Db, Adapter, anyShape, columnTypes, getClonedQueryData, singleQuote, columnsShapeToCode, codeToString,
|
|
1
|
+
import { getColumnTypes, addQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, getQueryAs, toSqlCacheKey, NotFoundError, relationQueryKey, Db, Adapter, anyShape, columnTypes, getClonedQueryData, singleQuote, columnsShapeToCode, codeToString, quoteObjectKey, primaryKeyToCode, indexToCode, foreignKeyToCode, columnIndexesToCode, columnForeignKeysToCode, addCode, columnDefaultArgumentToCode } from 'pqb';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import path__default from 'path';
|
|
4
4
|
import fs from 'fs/promises';
|
|
@@ -1944,20 +1944,32 @@ const changeColumn = ({ changes, t, spaces }, changeItem, prop) => {
|
|
|
1944
1944
|
}
|
|
1945
1945
|
}
|
|
1946
1946
|
const changedProps = {};
|
|
1947
|
+
const replaced = {};
|
|
1947
1948
|
for (const item of items.reverse()) {
|
|
1948
1949
|
if (!ts.is.propertyAccess(item.expression))
|
|
1949
1950
|
continue;
|
|
1950
1951
|
const { name } = item.expression;
|
|
1951
|
-
|
|
1952
|
+
let key = name.escapedText.toString();
|
|
1953
|
+
if (key === "index")
|
|
1954
|
+
key = "indexes";
|
|
1955
|
+
else if (key === "foreignKey")
|
|
1956
|
+
key = "foreignKeys";
|
|
1952
1957
|
if (!propsToChange[key])
|
|
1953
1958
|
continue;
|
|
1954
|
-
|
|
1955
|
-
if (
|
|
1956
|
-
const code =
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1959
|
+
let remove = true;
|
|
1960
|
+
if (!replaced[key]) {
|
|
1961
|
+
const code = getColumnMethodArgs(to, key);
|
|
1962
|
+
if (code) {
|
|
1963
|
+
changes.replace(
|
|
1964
|
+
item.expression.expression.end,
|
|
1965
|
+
item.end,
|
|
1966
|
+
codeToString(code, spaces + " ", " ").trim()
|
|
1967
|
+
);
|
|
1968
|
+
replaced[key] = true;
|
|
1969
|
+
remove = false;
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
if (remove) {
|
|
1961
1973
|
changes.remove(item.expression.expression.end, item.end);
|
|
1962
1974
|
}
|
|
1963
1975
|
changedProps[key] = true;
|
|
@@ -1966,12 +1978,9 @@ const changeColumn = ({ changes, t, spaces }, changeItem, prop) => {
|
|
|
1966
1978
|
for (const key in propsToChange) {
|
|
1967
1979
|
if (changedProps[key])
|
|
1968
1980
|
continue;
|
|
1969
|
-
const
|
|
1970
|
-
if (
|
|
1971
|
-
|
|
1972
|
-
addCode(code, value);
|
|
1973
|
-
addCode(code, ")");
|
|
1974
|
-
append += codeToString(code, "", " ").trim();
|
|
1981
|
+
const code = getColumnMethodArgs(to, key);
|
|
1982
|
+
if (code) {
|
|
1983
|
+
append += codeToString(code, spaces + " ", " ").trim();
|
|
1975
1984
|
}
|
|
1976
1985
|
}
|
|
1977
1986
|
if (append) {
|
|
@@ -2026,15 +2035,22 @@ const getColumnMethodArgs = (to, key) => {
|
|
|
2026
2035
|
const value = to[key];
|
|
2027
2036
|
if (!value)
|
|
2028
2037
|
return;
|
|
2038
|
+
if (key === "indexes") {
|
|
2039
|
+
return columnIndexesToCode(value);
|
|
2040
|
+
}
|
|
2041
|
+
if (key === "foreignKeys") {
|
|
2042
|
+
return columnForeignKeysToCode(value);
|
|
2043
|
+
}
|
|
2044
|
+
const code = [`.${key}(`];
|
|
2029
2045
|
if (key === "collate" || key === "compression") {
|
|
2030
|
-
|
|
2046
|
+
addCode(code, singleQuote(value));
|
|
2031
2047
|
} else if (key === "default") {
|
|
2032
|
-
|
|
2033
|
-
} else if (key
|
|
2034
|
-
return "";
|
|
2035
|
-
} else {
|
|
2048
|
+
addCode(code, columnDefaultArgumentToCode(value));
|
|
2049
|
+
} else if (key !== "nullable" && key !== "primaryKey") {
|
|
2036
2050
|
return;
|
|
2037
2051
|
}
|
|
2052
|
+
addCode(code, ")");
|
|
2053
|
+
return code;
|
|
2038
2054
|
};
|
|
2039
2055
|
const dropMatchingIndexes = (context, prop, i, call, items) => {
|
|
2040
2056
|
if (!items.length)
|