orchid-orm 1.4.21 → 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 +21 -0
- package/dist/index.esm.js +64 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +63 -22
- 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/src/codegen/updateTableFile/createTable.test.ts +55 -21
- package/src/codegen/updateTableFile/createTable.ts +8 -1
- package/src/codegen/updateTableFile/renameTable.test.ts +81 -1
- package/src/codegen/updateTableFile/renameTable.ts +29 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
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
|
+
|
|
16
|
+
## 1.4.22
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Change inner aspects of columns
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
- pqb@0.8.5
|
|
23
|
+
|
|
3
24
|
## 1.4.21
|
|
4
25
|
|
|
5
26
|
### 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';
|
|
@@ -1727,7 +1727,11 @@ const createTable = async (_a) => {
|
|
|
1727
1727
|
]);
|
|
1728
1728
|
const tablePath = params.tablePath(ast.name);
|
|
1729
1729
|
const baseTablePath = getImportPath(tablePath, params.baseTablePath);
|
|
1730
|
-
const props = [
|
|
1730
|
+
const props = [];
|
|
1731
|
+
if (ast.schema) {
|
|
1732
|
+
props.push(`schema = ${singleQuote(ast.schema)};`);
|
|
1733
|
+
}
|
|
1734
|
+
props.push(`table = ${singleQuote(ast.name)};`);
|
|
1731
1735
|
if (ast.noPrimaryKey === "ignore") {
|
|
1732
1736
|
props.push("noPrimaryKey = true;");
|
|
1733
1737
|
}
|
|
@@ -1940,20 +1944,32 @@ const changeColumn = ({ changes, t, spaces }, changeItem, prop) => {
|
|
|
1940
1944
|
}
|
|
1941
1945
|
}
|
|
1942
1946
|
const changedProps = {};
|
|
1947
|
+
const replaced = {};
|
|
1943
1948
|
for (const item of items.reverse()) {
|
|
1944
1949
|
if (!ts.is.propertyAccess(item.expression))
|
|
1945
1950
|
continue;
|
|
1946
1951
|
const { name } = item.expression;
|
|
1947
|
-
|
|
1952
|
+
let key = name.escapedText.toString();
|
|
1953
|
+
if (key === "index")
|
|
1954
|
+
key = "indexes";
|
|
1955
|
+
else if (key === "foreignKey")
|
|
1956
|
+
key = "foreignKeys";
|
|
1948
1957
|
if (!propsToChange[key])
|
|
1949
1958
|
continue;
|
|
1950
|
-
|
|
1951
|
-
if (
|
|
1952
|
-
const code =
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
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) {
|
|
1957
1973
|
changes.remove(item.expression.expression.end, item.end);
|
|
1958
1974
|
}
|
|
1959
1975
|
changedProps[key] = true;
|
|
@@ -1962,12 +1978,9 @@ const changeColumn = ({ changes, t, spaces }, changeItem, prop) => {
|
|
|
1962
1978
|
for (const key in propsToChange) {
|
|
1963
1979
|
if (changedProps[key])
|
|
1964
1980
|
continue;
|
|
1965
|
-
const
|
|
1966
|
-
if (
|
|
1967
|
-
|
|
1968
|
-
addCode(code, value);
|
|
1969
|
-
addCode(code, ")");
|
|
1970
|
-
append += codeToString(code, "", " ").trim();
|
|
1981
|
+
const code = getColumnMethodArgs(to, key);
|
|
1982
|
+
if (code) {
|
|
1983
|
+
append += codeToString(code, spaces + " ", " ").trim();
|
|
1971
1984
|
}
|
|
1972
1985
|
}
|
|
1973
1986
|
if (append) {
|
|
@@ -2022,15 +2035,22 @@ const getColumnMethodArgs = (to, key) => {
|
|
|
2022
2035
|
const value = to[key];
|
|
2023
2036
|
if (!value)
|
|
2024
2037
|
return;
|
|
2038
|
+
if (key === "indexes") {
|
|
2039
|
+
return columnIndexesToCode(value);
|
|
2040
|
+
}
|
|
2041
|
+
if (key === "foreignKeys") {
|
|
2042
|
+
return columnForeignKeysToCode(value);
|
|
2043
|
+
}
|
|
2044
|
+
const code = [`.${key}(`];
|
|
2025
2045
|
if (key === "collate" || key === "compression") {
|
|
2026
|
-
|
|
2046
|
+
addCode(code, singleQuote(value));
|
|
2027
2047
|
} else if (key === "default") {
|
|
2028
|
-
|
|
2029
|
-
} else if (key
|
|
2030
|
-
return "";
|
|
2031
|
-
} else {
|
|
2048
|
+
addCode(code, columnDefaultArgumentToCode(value));
|
|
2049
|
+
} else if (key !== "nullable" && key !== "primaryKey") {
|
|
2032
2050
|
return;
|
|
2033
2051
|
}
|
|
2052
|
+
addCode(code, ")");
|
|
2053
|
+
return code;
|
|
2034
2054
|
};
|
|
2035
2055
|
const dropMatchingIndexes = (context, prop, i, call, items) => {
|
|
2036
2056
|
if (!items.length)
|
|
@@ -2170,17 +2190,38 @@ const renameTable = async (_a) => {
|
|
|
2170
2190
|
const changes = new FileChanges(content);
|
|
2171
2191
|
const statements = ts.getStatements(content);
|
|
2172
2192
|
const className = toPascalCase(ast.from);
|
|
2193
|
+
const changeSchema = ast.fromSchema !== ast.toSchema;
|
|
2173
2194
|
for (const node of ts.class.iterate(statements)) {
|
|
2174
2195
|
if (((_a2 = node.name) == null ? void 0 : _a2.escapedText) !== className)
|
|
2175
2196
|
continue;
|
|
2197
|
+
const addSchema = changeSchema && ast.toSchema && !node.members.some((member) => ts.prop.getName(member) === "schema");
|
|
2198
|
+
if (addSchema && ast.toSchema) {
|
|
2199
|
+
changes.add(
|
|
2200
|
+
node.members.pos,
|
|
2201
|
+
`
|
|
2202
|
+
schema = ${singleQuote(ast.toSchema)};`
|
|
2203
|
+
);
|
|
2204
|
+
}
|
|
2176
2205
|
for (const member of node.members) {
|
|
2177
2206
|
const name = ts.prop.getName(member);
|
|
2178
|
-
if (name !== "table")
|
|
2207
|
+
if (name !== "table" && !(changeSchema && name === "schema"))
|
|
2179
2208
|
continue;
|
|
2180
2209
|
const { initializer: value } = member;
|
|
2181
2210
|
if (!value)
|
|
2182
2211
|
continue;
|
|
2183
|
-
|
|
2212
|
+
if (name === "schema") {
|
|
2213
|
+
if (ast.toSchema) {
|
|
2214
|
+
changes.replace(
|
|
2215
|
+
value.pos,
|
|
2216
|
+
value.end,
|
|
2217
|
+
` ${singleQuote(ast.toSchema)}`
|
|
2218
|
+
);
|
|
2219
|
+
} else {
|
|
2220
|
+
changes.remove(member.pos, member.end);
|
|
2221
|
+
}
|
|
2222
|
+
} else {
|
|
2223
|
+
changes.replace(value.pos, value.end, ` ${singleQuote(ast.to)}`);
|
|
2224
|
+
}
|
|
2184
2225
|
}
|
|
2185
2226
|
}
|
|
2186
2227
|
await fs.writeFile(params.tablePath(ast.to), changes.apply());
|