Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: insert and update query builder to handle mssql geometry column …
…correctly (#5947) * [UPDATE] Update insert and update query builder to handle mssql geometry column with SRID properly * [FIX] Fix indentation with spaces * [FIX] Fix semicolon, and quota characters * [FIX] Fix semicolon Co-authored-by: Paul Kwok <wkkwok@uacs.hk>
- Loading branch information
1 parent
2fd0a8a
commit 87cc6f4
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from "../../../../../src"; | ||
|
||
@Entity() | ||
export class FeatureWithoutSRID { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@Column({ type: "geometry" }) | ||
shape: string; | ||
|
||
} | ||
|
||
@Entity() | ||
export class FeatureWithSRID { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@Column({ type: "geometry", srid: 2326 }) | ||
shape: string; | ||
|
||
} |
108 changes: 108 additions & 0 deletions
108
test/core/column-kinds/geometry-column/geometry-column.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { expect } from "chai"; | ||
import "reflect-metadata"; | ||
import { Connection } from "../../../../src"; | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../../utils/test-utils"; | ||
import { FeatureWithoutSRID, FeatureWithSRID } from "./entity/Feature"; | ||
|
||
describe("column kinds > geometry column", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["mssql"] | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
|
||
|
||
it("geometry column with SRID defined should be saved without error for valid WKT input", () => Promise.all(connections.map(async connection => { | ||
const featureRepository = connection.getRepository(FeatureWithSRID); | ||
|
||
// save a new feature | ||
const feature = new FeatureWithSRID(); | ||
feature.name = "feature"; | ||
feature.shape = "POINT (828365.16700000037 823377.14699999988)"; | ||
await featureRepository.save(feature); | ||
|
||
// load and check if createdAt was a value set by us | ||
const loadedfeature = await featureRepository.findOne(); | ||
expect(loadedfeature).to.be.not.empty; | ||
expect(loadedfeature!.name).to.be.eql("feature"); | ||
expect(loadedfeature!.shape).to.be.eql("POINT (828365.16700000037 823377.14699999988)"); | ||
|
||
}))); | ||
|
||
it("geometry column with SRID defined should be updated without error for valid WKT input", () => Promise.all(connections.map(async connection => { | ||
const featureRepository = connection.getRepository(FeatureWithSRID); | ||
|
||
// save a new feature | ||
const feature = new FeatureWithSRID(); | ||
feature.name = "feature"; | ||
feature.shape = "POINT (828365.16700000037 823377.14699999988)"; | ||
await featureRepository.save(feature); | ||
|
||
// load and check if createdAt was a value set by us | ||
const loadedfeature = await featureRepository.findOne(); | ||
expect(loadedfeature).to.be.not.empty; | ||
expect(loadedfeature!.name).to.be.eql("feature"); | ||
expect(loadedfeature!.shape).to.be.eql("POINT (828365.16700000037 823377.14699999988)"); | ||
|
||
feature.shape = "POINT (728365.16700000037 723377.14699999988)"; | ||
await featureRepository.save(feature); | ||
|
||
// load and check if createdAt is a date (generated by db) | ||
const updatedfeature = await featureRepository.findOne(); | ||
expect(updatedfeature).to.be.not.empty; | ||
expect(updatedfeature!.name).to.be.eql("feature"); | ||
expect(updatedfeature!.shape).to.be.eql("POINT (728365.16700000037 723377.14699999988)"); | ||
|
||
}))); | ||
|
||
it("geometry column with no SRID should be saved without error for valid WKT input", () => Promise.all(connections.map(async connection => { | ||
const featureRepository = connection.getRepository(FeatureWithoutSRID); | ||
|
||
// save a new feature | ||
const feature = new FeatureWithoutSRID(); | ||
feature.name = "feature"; | ||
feature.shape = "POINT (0 0)"; | ||
await featureRepository.save(feature); | ||
|
||
// load and check if createdAt is a date (generated by db) | ||
const loadedfeature = await featureRepository.findOne(); | ||
expect(loadedfeature).to.be.not.empty; | ||
expect(loadedfeature!.name).to.be.eql("feature"); | ||
expect(loadedfeature!.shape).to.be.eql("POINT (0 0)"); | ||
}))); | ||
|
||
it("geometry column with no SRID should be updated without error for valid WKT input", () => Promise.all(connections.map(async connection => { | ||
const featureRepository = connection.getRepository(FeatureWithoutSRID); | ||
|
||
// save a new feature | ||
const feature = new FeatureWithoutSRID(); | ||
feature.name = "feature"; | ||
feature.shape = "POINT (0 0)"; | ||
await featureRepository.save(feature); | ||
|
||
// load and check if createdAt is a date (generated by db) | ||
const loadedfeature = await featureRepository.findOne(); | ||
expect(loadedfeature).to.be.not.empty; | ||
expect(loadedfeature!.name).to.be.eql("feature"); | ||
expect(loadedfeature!.shape).to.be.eql("POINT (0 0)"); | ||
|
||
feature.shape = "POINT (0.5 0.5)"; | ||
await featureRepository.save(feature); | ||
|
||
// load and check if createdAt is a date (generated by db) | ||
const updatedfeature = await featureRepository.findOne(); | ||
expect(updatedfeature).to.be.not.empty; | ||
expect(updatedfeature!.name).to.be.eql("feature"); | ||
expect(updatedfeature!.shape).to.be.eql("POINT (0.5 0.5)"); | ||
|
||
}))); | ||
|
||
}); |