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/dist/index.js
CHANGED
|
@@ -1971,20 +1971,32 @@ const changeColumn = ({ changes, t, spaces }, changeItem, prop) => {
|
|
|
1971
1971
|
}
|
|
1972
1972
|
}
|
|
1973
1973
|
const changedProps = {};
|
|
1974
|
+
const replaced = {};
|
|
1974
1975
|
for (const item of items.reverse()) {
|
|
1975
1976
|
if (!ts.is.propertyAccess(item.expression))
|
|
1976
1977
|
continue;
|
|
1977
1978
|
const { name } = item.expression;
|
|
1978
|
-
|
|
1979
|
+
let key = name.escapedText.toString();
|
|
1980
|
+
if (key === "index")
|
|
1981
|
+
key = "indexes";
|
|
1982
|
+
else if (key === "foreignKey")
|
|
1983
|
+
key = "foreignKeys";
|
|
1979
1984
|
if (!propsToChange[key])
|
|
1980
1985
|
continue;
|
|
1981
|
-
|
|
1982
|
-
if (
|
|
1983
|
-
const code =
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1986
|
+
let remove = true;
|
|
1987
|
+
if (!replaced[key]) {
|
|
1988
|
+
const code = getColumnMethodArgs(to, key);
|
|
1989
|
+
if (code) {
|
|
1990
|
+
changes.replace(
|
|
1991
|
+
item.expression.expression.end,
|
|
1992
|
+
item.end,
|
|
1993
|
+
pqb.codeToString(code, spaces + " ", " ").trim()
|
|
1994
|
+
);
|
|
1995
|
+
replaced[key] = true;
|
|
1996
|
+
remove = false;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
if (remove) {
|
|
1988
2000
|
changes.remove(item.expression.expression.end, item.end);
|
|
1989
2001
|
}
|
|
1990
2002
|
changedProps[key] = true;
|
|
@@ -1993,12 +2005,9 @@ const changeColumn = ({ changes, t, spaces }, changeItem, prop) => {
|
|
|
1993
2005
|
for (const key in propsToChange) {
|
|
1994
2006
|
if (changedProps[key])
|
|
1995
2007
|
continue;
|
|
1996
|
-
const
|
|
1997
|
-
if (
|
|
1998
|
-
|
|
1999
|
-
pqb.addCode(code, value);
|
|
2000
|
-
pqb.addCode(code, ")");
|
|
2001
|
-
append += pqb.codeToString(code, "", " ").trim();
|
|
2008
|
+
const code = getColumnMethodArgs(to, key);
|
|
2009
|
+
if (code) {
|
|
2010
|
+
append += pqb.codeToString(code, spaces + " ", " ").trim();
|
|
2002
2011
|
}
|
|
2003
2012
|
}
|
|
2004
2013
|
if (append) {
|
|
@@ -2053,15 +2062,22 @@ const getColumnMethodArgs = (to, key) => {
|
|
|
2053
2062
|
const value = to[key];
|
|
2054
2063
|
if (!value)
|
|
2055
2064
|
return;
|
|
2065
|
+
if (key === "indexes") {
|
|
2066
|
+
return pqb.columnIndexesToCode(value);
|
|
2067
|
+
}
|
|
2068
|
+
if (key === "foreignKeys") {
|
|
2069
|
+
return pqb.columnForeignKeysToCode(value);
|
|
2070
|
+
}
|
|
2071
|
+
const code = [`.${key}(`];
|
|
2056
2072
|
if (key === "collate" || key === "compression") {
|
|
2057
|
-
|
|
2073
|
+
pqb.addCode(code, pqb.singleQuote(value));
|
|
2058
2074
|
} else if (key === "default") {
|
|
2059
|
-
|
|
2060
|
-
} else if (key
|
|
2061
|
-
return "";
|
|
2062
|
-
} else {
|
|
2075
|
+
pqb.addCode(code, pqb.columnDefaultArgumentToCode(value));
|
|
2076
|
+
} else if (key !== "nullable" && key !== "primaryKey") {
|
|
2063
2077
|
return;
|
|
2064
2078
|
}
|
|
2079
|
+
pqb.addCode(code, ")");
|
|
2080
|
+
return code;
|
|
2065
2081
|
};
|
|
2066
2082
|
const dropMatchingIndexes = (context, prop, i, call, items) => {
|
|
2067
2083
|
if (!items.length)
|