@entity-access/entity-access 1.0.121 → 1.0.123
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/decorators/Column.d.ts +6 -1
- package/dist/decorators/Column.d.ts.map +1 -1
- package/dist/decorators/Column.js +7 -0
- package/dist/decorators/Column.js.map +1 -1
- package/dist/decorators/IColumn.d.ts +3 -1
- package/dist/decorators/IColumn.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.d.ts.map +1 -1
- package/dist/drivers/base/BaseDriver.js +7 -1
- package/dist/drivers/base/BaseDriver.js.map +1 -1
- package/dist/migrations/Migrations.d.ts.map +1 -1
- package/dist/migrations/Migrations.js +9 -0
- package/dist/migrations/Migrations.js.map +1 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.d.ts.map +1 -1
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js +13 -3
- package/dist/migrations/postgres/PostgresAutomaticMigrations.js.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.d.ts.map +1 -1
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js +14 -2
- package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js.map +1 -1
- package/dist/model/changes/ChangeEntry.js +1 -1
- package/dist/model/changes/ChangeEntry.js.map +1 -1
- package/dist/query/ast/ExpressionToSql.js +1 -1
- package/dist/query/ast/ExpressionToSql.js.map +1 -1
- package/dist/tests/model/ShoppingContext.d.ts +1 -0
- package/dist/tests/model/ShoppingContext.d.ts.map +1 -1
- package/dist/tests/model/ShoppingContext.js +13 -7
- package/dist/tests/model/ShoppingContext.js.map +1 -1
- package/dist/tests/model/UseFile.js +1 -1
- package/dist/tests/model/UseFile.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/decorators/Column.ts +13 -3
- package/src/decorators/IColumn.ts +5 -1
- package/src/drivers/base/BaseDriver.ts +7 -1
- package/src/migrations/Migrations.ts +11 -0
- package/src/migrations/postgres/PostgresAutomaticMigrations.ts +17 -3
- package/src/migrations/sql-server/SqlServerAutomaticMigrations.ts +16 -2
- package/src/model/changes/ChangeEntry.ts +1 -1
- package/src/query/ast/ExpressionToSql.ts +1 -1
- package/src/tests/model/ShoppingContext.ts +12 -7
- package/src/tests/model/UseFile.ts +1 -1
|
@@ -56,12 +56,22 @@ export default class SqlServerAutomaticMigrations extends SqlServerMigrations {
|
|
|
56
56
|
for (const iterator of nonKeyColumns) {
|
|
57
57
|
const columnName = iterator.columnName;
|
|
58
58
|
let def = `IF COL_LENGTH(${ SqlServerLiteral.escapeLiteral(name)}, ${ SqlServerLiteral.escapeLiteral(columnName)}) IS NULL ALTER TABLE ${name} ADD ${columnName} `;
|
|
59
|
+
|
|
60
|
+
if (iterator.computed) {
|
|
61
|
+
def += ` AS ${iterator.computed} ${iterator.stored ? "PERSISTED" : ""}`;
|
|
62
|
+
await driver.executeQuery(def + ";");
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
59
66
|
def += this.getColumnDefinition(iterator);
|
|
60
67
|
if (iterator.nullable === true) {
|
|
61
68
|
def += " NULL ";
|
|
62
69
|
} else {
|
|
63
70
|
def += " NOT NULL ";
|
|
64
71
|
}
|
|
72
|
+
if (iterator.computed) {
|
|
73
|
+
def += ` AS ${iterator.computed} ${iterator.stored ? "PERSISTED" : ""}`;
|
|
74
|
+
}
|
|
65
75
|
if (typeof iterator.default === "string") {
|
|
66
76
|
def += " DEFAULT " + iterator.default;
|
|
67
77
|
}
|
|
@@ -84,8 +94,12 @@ export default class SqlServerAutomaticMigrations extends SqlServerMigrations {
|
|
|
84
94
|
|
|
85
95
|
for (const iterator of keys) {
|
|
86
96
|
let def = iterator.columnName + " ";
|
|
87
|
-
if (iterator.
|
|
88
|
-
|
|
97
|
+
if (iterator.generated) {
|
|
98
|
+
switch(iterator.generated) {
|
|
99
|
+
case "identity":
|
|
100
|
+
def += `${this.getColumnDefinition(iterator)} NOT NULL IDENTITY(1,1)`;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
89
103
|
} else {
|
|
90
104
|
def += `${this.getColumnDefinition(iterator)} NOT NULL`;
|
|
91
105
|
}
|
|
@@ -81,7 +81,7 @@ export default class ChangeEntry<T = any> implements IChanges {
|
|
|
81
81
|
let keysSet = true;
|
|
82
82
|
let autoGenerate = false;
|
|
83
83
|
for (const iterator of keys) {
|
|
84
|
-
autoGenerate ||= iterator.
|
|
84
|
+
autoGenerate ||= iterator.generated as unknown as boolean;
|
|
85
85
|
if(entity[iterator.name] === void 0) {
|
|
86
86
|
keysSet = false;
|
|
87
87
|
}
|
|
@@ -444,7 +444,7 @@ export default class ExpressionToSql extends Visitor<ITextQuery> {
|
|
|
444
444
|
if (e.fields.length === 0) {
|
|
445
445
|
return [];
|
|
446
446
|
}
|
|
447
|
-
const fields = this.visitArray(e.fields)
|
|
447
|
+
const fields = this.visitArray(e.fields);
|
|
448
448
|
return prepare ` RETURNING ${fields}`;
|
|
449
449
|
}
|
|
450
450
|
|
|
@@ -5,6 +5,7 @@ import Table from "../../decorators/Table.js";
|
|
|
5
5
|
import Index from "../../decorators/Index.js";
|
|
6
6
|
import DateTime from "../../types/DateTime.js";
|
|
7
7
|
import { UserFile } from "./UseFile.js";
|
|
8
|
+
import Sql from "../../sql/Sql.js";
|
|
8
9
|
|
|
9
10
|
export const statusPublished = "published";
|
|
10
11
|
|
|
@@ -41,7 +42,7 @@ export class ShoppingContext extends EntityContext {
|
|
|
41
42
|
})
|
|
42
43
|
export class User {
|
|
43
44
|
|
|
44
|
-
@Column({ key: true ,
|
|
45
|
+
@Column({ key: true , generated: "identity", dataType: "BigInt" })
|
|
45
46
|
public userID: number;
|
|
46
47
|
|
|
47
48
|
@Column({})
|
|
@@ -80,6 +81,10 @@ export class Category {
|
|
|
80
81
|
@Column({ length: 200 })
|
|
81
82
|
public name: string;
|
|
82
83
|
|
|
84
|
+
|
|
85
|
+
@Column({ computed: (x) => Sql.text.lower(x.name)})
|
|
86
|
+
public lowerName: string;
|
|
87
|
+
|
|
83
88
|
@Column({ dataType: "Char", length: 200, nullable: true })
|
|
84
89
|
@RelateTo(Category, {
|
|
85
90
|
property: (c) => c.parent,
|
|
@@ -118,7 +123,7 @@ export class UserProfile {
|
|
|
118
123
|
@Table("ProfilePhotos")
|
|
119
124
|
export class ProfilePhoto {
|
|
120
125
|
|
|
121
|
-
@Column({ key: true, dataType: "BigInt",
|
|
126
|
+
@Column({ key: true, dataType: "BigInt", generated: "identity" })
|
|
122
127
|
public photoID: number;
|
|
123
128
|
|
|
124
129
|
@Column ({ dataType: "BigInt"})
|
|
@@ -162,7 +167,7 @@ export class UserCategory {
|
|
|
162
167
|
@Table("Products")
|
|
163
168
|
export class Product {
|
|
164
169
|
|
|
165
|
-
@Column({ key: true,
|
|
170
|
+
@Column({ key: true, generated: "identity", dataType: "BigInt" })
|
|
166
171
|
public productID: number;
|
|
167
172
|
|
|
168
173
|
@Column()
|
|
@@ -189,7 +194,7 @@ export class Product {
|
|
|
189
194
|
@Table("ProductCategories")
|
|
190
195
|
export class ProductCategory {
|
|
191
196
|
|
|
192
|
-
@Column({ key: true, dataType: "BigInt",
|
|
197
|
+
@Column({ key: true, dataType: "BigInt", generated: "identity" })
|
|
193
198
|
public productCategoryID: number;
|
|
194
199
|
|
|
195
200
|
@Column({ dataType: "BigInt" })
|
|
@@ -214,7 +219,7 @@ export class ProductCategory {
|
|
|
214
219
|
@Table("ProductPrices")
|
|
215
220
|
export class ProductPrice {
|
|
216
221
|
|
|
217
|
-
@Column({ key: true,
|
|
222
|
+
@Column({ key: true, generated: "identity", dataType: "BigInt"})
|
|
218
223
|
public priceID: number;
|
|
219
224
|
|
|
220
225
|
@Column()
|
|
@@ -248,7 +253,7 @@ export class ProductPrice {
|
|
|
248
253
|
})
|
|
249
254
|
export class Order {
|
|
250
255
|
|
|
251
|
-
@Column({ key: true,
|
|
256
|
+
@Column({ key: true, generated: "identity", dataType: "BigInt"})
|
|
252
257
|
public orderID: number;
|
|
253
258
|
|
|
254
259
|
@Column()
|
|
@@ -273,7 +278,7 @@ export class Order {
|
|
|
273
278
|
@Table("OrderItems")
|
|
274
279
|
export class OrderItem {
|
|
275
280
|
|
|
276
|
-
@Column({ key: true,
|
|
281
|
+
@Column({ key: true, generated: "identity", dataType: "BigInt"})
|
|
277
282
|
public orderItemID: number;
|
|
278
283
|
|
|
279
284
|
@Column()
|
|
@@ -6,7 +6,7 @@ import { User } from "./ShoppingContext.js";
|
|
|
6
6
|
@Table("UserFiles")
|
|
7
7
|
export class UserFile {
|
|
8
8
|
|
|
9
|
-
@Column({ dataType: "BigInt", key: true,
|
|
9
|
+
@Column({ dataType: "BigInt", key: true, generated: "identity" })
|
|
10
10
|
public fileID: number;
|
|
11
11
|
|
|
12
12
|
@Column({ dataType: "BigInt"})
|