@entity-access/entity-access 1.1.6 → 1.1.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.
Files changed (41) hide show
  1. package/.github/workflows/node.yml +1 -1
  2. package/dist/compiler/postgres/PostgreSqlMethodTransformer.js +2 -2
  3. package/dist/compiler/postgres/PostgreSqlMethodTransformer.js.map +1 -1
  4. package/dist/decorators/IIndex.d.ts +2 -0
  5. package/dist/decorators/IIndex.d.ts.map +1 -1
  6. package/dist/decorators/ISqlType.d.ts +2 -6
  7. package/dist/decorators/ISqlType.d.ts.map +1 -1
  8. package/dist/decorators/Index.d.ts +1 -1
  9. package/dist/decorators/Index.d.ts.map +1 -1
  10. package/dist/decorators/Index.js +2 -1
  11. package/dist/decorators/Index.js.map +1 -1
  12. package/dist/migrations/Migrations.d.ts +1 -0
  13. package/dist/migrations/Migrations.d.ts.map +1 -1
  14. package/dist/migrations/Migrations.js +12 -0
  15. package/dist/migrations/Migrations.js.map +1 -1
  16. package/dist/migrations/postgres/PostgresAutomaticMigrations.d.ts.map +1 -1
  17. package/dist/migrations/postgres/PostgresAutomaticMigrations.js +6 -2
  18. package/dist/migrations/postgres/PostgresAutomaticMigrations.js.map +1 -1
  19. package/dist/migrations/postgres/PostgresMigrations.d.ts +2 -1
  20. package/dist/migrations/postgres/PostgresMigrations.d.ts.map +1 -1
  21. package/dist/migrations/postgres/PostgresMigrations.js +5 -4
  22. package/dist/migrations/postgres/PostgresMigrations.js.map +1 -1
  23. package/dist/migrations/sql-server/SqlServerAutomaticMigrations.d.ts.map +1 -1
  24. package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js +3 -2
  25. package/dist/migrations/sql-server/SqlServerAutomaticMigrations.js.map +1 -1
  26. package/dist/migrations/sql-server/SqlServerMigrations.d.ts +1 -1
  27. package/dist/migrations/sql-server/SqlServerMigrations.d.ts.map +1 -1
  28. package/dist/migrations/sql-server/SqlServerMigrations.js +2 -4
  29. package/dist/migrations/sql-server/SqlServerMigrations.js.map +1 -1
  30. package/dist/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +1 -1
  32. package/src/compiler/postgres/PostgreSqlMethodTransformer.ts +2 -2
  33. package/src/decorators/IIndex.ts +2 -0
  34. package/src/decorators/ISqlType.ts +2 -7
  35. package/src/decorators/Index.ts +2 -0
  36. package/src/migrations/Migrations.ts +15 -0
  37. package/src/migrations/postgres/PostgresAutomaticMigrations.ts +8 -2
  38. package/src/migrations/postgres/PostgresMigrations.ts +6 -4
  39. package/src/migrations/sql-server/SqlServerAutomaticMigrations.ts +5 -2
  40. package/src/migrations/sql-server/SqlServerMigrations.ts +2 -4
  41. package/tests/local-unit-tests/docker-compose.yml +1 -1
@@ -14,6 +14,7 @@ export default function Index<T>(
14
14
  unique,
15
15
  include,
16
16
  indexType,
17
+ spatial,
17
18
  filter
18
19
  }
19
20
  : IIndexDef<T>) {
@@ -27,6 +28,7 @@ export default function Index<T>(
27
28
  include: include ? include.map(NameParser.parseMember) : void 0,
28
29
  dropNames,
29
30
  indexType,
31
+ spatial,
30
32
  filter,
31
33
  columns
32
34
  };
@@ -55,6 +55,8 @@ export default abstract class Migrations {
55
55
  }
56
56
  }
57
57
 
58
+ let hasGeoSpatialTypes = false;
59
+
58
60
  for (const s of model.sources.values()) {
59
61
  const type = s[modelSymbol] as EntityType;
60
62
 
@@ -63,6 +65,11 @@ export default abstract class Migrations {
63
65
  }
64
66
 
65
67
  for (const column of type.columns) {
68
+ switch(column.dataType) {
69
+ case "Geography":
70
+ hasGeoSpatialTypes = true;
71
+ break;
72
+ }
66
73
  if (column.computed && typeof column.computed !== "string") {
67
74
  // parse..
68
75
  const source = context.query(type.typeClass) as EntityQuery<any>;
@@ -79,6 +86,10 @@ export default abstract class Migrations {
79
86
  }
80
87
  }
81
88
 
89
+ if (hasGeoSpatialTypes) {
90
+ await this.enableGeoSpatialTypes();
91
+ }
92
+
82
93
  const schema = await this.getSchema(type);
83
94
 
84
95
  await this.migrateTable(context, type);
@@ -149,6 +160,10 @@ export default abstract class Migrations {
149
160
  return true;
150
161
  }
151
162
 
163
+ async enableGeoSpatialTypes() {
164
+ // do nothing...
165
+ }
166
+
152
167
  async hasVersion(context: EntityContext, name: string, version: string, table: string) {
153
168
  const { quote, escapeLiteral } = this.compiler;
154
169
 
@@ -124,9 +124,15 @@ export default class PostgresAutomaticMigrations extends PostgresMigrations {
124
124
  break;
125
125
  }
126
126
  }
127
- columns.push(`${columnName} ${operatorClass} ${column.descending ? "DESC" : "ASC"}`);
127
+ columns.push(`${columnName} ${operatorClass} ${ index.spatial ? "" : (column.descending ? "DESC" : "ASC")}`);
128
128
  }
129
- let query = `CREATE ${index.unique ? "UNIQUE" : ""} INDEX IF NOT EXISTS ${indexName} ON ${name} ( ${columns.join(", ")})`;
129
+ let query = `CREATE ${index.unique ? "UNIQUE" : ""} INDEX IF NOT EXISTS ${indexName} ON ${name}`;
130
+
131
+ if (index.spatial) {
132
+ query += " USING GIST ";
133
+ }
134
+
135
+ query += ` ( ${columns.join(", ")})`;
130
136
 
131
137
  if (index.include) {
132
138
  query += ` INCLUDE (${index.include.join(",")})`;
@@ -77,6 +77,10 @@ export default abstract class PostgresMigrations extends Migrations {
77
77
  return new ExistingSchema(false, { columns, foreignKeys, indexes, constraints });
78
78
  }
79
79
 
80
+ async enableGeoSpatialTypes(): Promise<void> {
81
+ await this.connection.executeQuery(`CREATE EXTENSION IF NOT EXISTS postgis;`);
82
+ }
83
+
80
84
  protected getColumnDefinition(iterator: IColumn) {
81
85
  if (iterator.dataType === "Decimal") {
82
86
  if (iterator.precision && iterator.scale) {
@@ -123,10 +127,8 @@ export default abstract class PostgresMigrations extends Migrations {
123
127
  return "jsonb";
124
128
  case "UUID":
125
129
  return "uuid";
126
- case "Geometry":
127
- return "geometry";
128
- case "Point":
129
- return "point";
130
+ case "Geography":
131
+ return "geography";
130
132
  }
131
133
  const a: never = iterator.dataType;
132
134
  throw new Error("Not Defined");
@@ -124,11 +124,14 @@ export default class SqlServerAutomaticMigrations extends SqlServerMigrations {
124
124
  const columns = [];
125
125
  for (const column of index.columns) {
126
126
  const columnName = column.name;
127
- columns.push(`${columnName} ${column.descending ? "DESC" : "ASC"}`);
127
+ columns.push(`${columnName} ${ index.spatial ? "" : (column.descending ? "DESC" : "ASC")}`);
128
128
  }
129
+
130
+ const indexType = index.spatial ? " SPATIAL " : "";
131
+
129
132
  let query = `IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = '${indexName}' AND object_id = OBJECT_ID('${name}'))
130
133
  BEGIN
131
- CREATE ${index.unique ? "UNIQUE" : ""} INDEX ${indexName} ON ${name} ( ${columns.join(", ")})`;
134
+ CREATE ${index.unique ? "UNIQUE" : ""} ${indexType} INDEX ${indexName} ON ${name} ( ${columns.join(", ")})`;
132
135
 
133
136
  if (index.include) {
134
137
  query += ` INCLUDE (${index.include.join(",")})`;
@@ -139,10 +139,8 @@ export default abstract class SqlServerMigrations extends Migrations {
139
139
  return "jsonb";
140
140
  case "UUID":
141
141
  return "UniqueIdentifier";
142
- case "Geometry":
143
- return "geometry";
144
- case "Point":
145
- return "geometry";
142
+ case "Geography":
143
+ return "geography";
146
144
  }
147
145
  const a: never = iterator.dataType;
148
146
  throw new Error("Not Defined");
@@ -11,7 +11,7 @@ services:
11
11
  ports:
12
12
  - 1433:1433
13
13
  postgresdb:
14
- image: postgres:alpine
14
+ image: postgis/postgis:18-3.6-alpine
15
15
  container_name: pg-test
16
16
  restart: unless-stopped
17
17
  environment: