-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support spatial types of MySQL 8+ (#4794)
* add `legacySpatialSupport` option for replacing dropped functions to new ones * use srid column option like PostgreSQL Close #3702
- Loading branch information
Showing
10 changed files
with
156 additions
and
5 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
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
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,13 @@ | ||
import {Entity, PrimaryGeneratedColumn} from "../../../../src"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
|
||
@Entity() | ||
export class LetterBox { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column({ type: "point", srid: 4326 }) | ||
coord: string; | ||
|
||
} |
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,104 @@ | ||
import "reflect-metadata"; | ||
import {createTestingConnections, closeTestingConnections} from "../../utils/test-utils"; | ||
import {Connection} from "../../../src/connection/Connection"; | ||
import {expect} from "chai"; | ||
import {LetterBox} from "./entity/LetterBox"; | ||
|
||
// Another related path: test/functional/spatial | ||
describe("github issues > #3702 MySQL Spatial Type Support : GeomFromText function is not supported", () => { | ||
|
||
describe("when legacySpatialSupport: true", () => { | ||
let connections: Connection[]; | ||
|
||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["mysql"], | ||
dropSchema: true, | ||
schemaCreate: true, | ||
driverSpecific: { | ||
// it's default | ||
// legacySpatialSupport: true, | ||
}, | ||
})); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should use GeomFromText", () => Promise.all(connections.map(async connection => { | ||
let queryBuilder = connection.createQueryBuilder().insert(); | ||
queryBuilder.into(LetterBox).values({ coord: "POINT(20 30)" }); | ||
const sql = queryBuilder.getSql(); | ||
|
||
expect(sql).includes("GeomFromText"); | ||
expect(sql).not.includes("ST_GeomFromText"); | ||
|
||
await queryBuilder.execute(); | ||
}))); | ||
|
||
|
||
it("should provide SRID", () => Promise.all(connections.map(async connection => { | ||
let queryBuilder = connection.createQueryBuilder().insert(); | ||
queryBuilder.into(LetterBox).values({ coord: "POINT(25 100)" }); | ||
const sql = queryBuilder.getSql(); | ||
|
||
expect(sql).includes("4326"); | ||
|
||
await queryBuilder.execute(); | ||
}))); | ||
|
||
it("should use AsText", () => Promise.all(connections.map(async connection => { | ||
const repository = connection.getRepository(LetterBox); | ||
let queryBuilder = repository.createQueryBuilder("letterBox").select(["letterBox"]); | ||
const sql = queryBuilder.getSql(); | ||
|
||
expect(sql).includes("AsText"); | ||
expect(sql).not.includes("ST_AsText"); | ||
|
||
await queryBuilder.getMany(); | ||
}))); | ||
}); | ||
|
||
|
||
describe("when legacySpatialSupport: false", () => { | ||
let connections: Connection[]; | ||
|
||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["mysql"], | ||
dropSchema: true, | ||
schemaCreate: true, | ||
driverSpecific: { | ||
legacySpatialSupport: false, | ||
} | ||
})); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should use ST_GeomFromText", () => Promise.all(connections.map(async connection => { | ||
let queryBuilder = connection.createQueryBuilder().insert(); | ||
queryBuilder.into(LetterBox).values({ coord: "POINT(20 30)" }); | ||
const sql = queryBuilder.getSql(); | ||
|
||
expect(sql).includes("ST_GeomFromText"); | ||
|
||
await queryBuilder.execute(); | ||
}))); | ||
|
||
it("should provide SRID", () => Promise.all(connections.map(async connection => { | ||
let queryBuilder = connection.createQueryBuilder().insert(); | ||
queryBuilder.into(LetterBox).values({ coord: "POINT(25 100)" }); | ||
const sql = queryBuilder.getSql(); | ||
|
||
expect(sql).includes("4326"); | ||
|
||
await queryBuilder.execute(); | ||
}))); | ||
|
||
it("should use ST_AsText", () => Promise.all(connections.map(async connection => { | ||
const repository = connection.getRepository(LetterBox); | ||
let queryBuilder = repository.createQueryBuilder("letterBox").select(["letterBox"]); | ||
const sql = queryBuilder.getSql(); | ||
|
||
expect(sql).includes("ST_AsText"); | ||
|
||
await queryBuilder.getMany(); | ||
}))); | ||
}); | ||
}); |