Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository.prototype.save results for geography types are not consistent with find methods #10852

Open
1 of 18 tasks
mkhstar opened this issue Apr 24, 2024 · 0 comments
Open
1 of 18 tasks

Comments

@mkhstar
Copy link

mkhstar commented Apr 24, 2024

Issue description

Geography column types such as geometry, point etc save method returns a hex representation of the geography type in the database, while .find methods return the json representation of it

Expected Behavior

I expect .save with method results to be consistent with what is returned in the find methods. I would like to also get json when i use .save method

Actual Behavior

A hex representation of the geography type is returned.

Steps to reproduce

Given the entity below

import type { Geometry } from "geojson";

@Entity 
class MyEntity{

@PrimaryGeneratedColumn()
 public id: number;

  @Column({
    type: "geography",
    spatialFeatureType: "Geometry",
    srid: 4326,
    nullable: true,
    default: null,
  })
  public geometry: Geometry | null;
}

Example usage below with expectation and actual

const myEntityRepository = datasource.getRepository(MyEntity);

const polygon = {
  type: "Polygon",
  coordinates: [
    [
      [15.308124039486808, 49.80101227755168],
      [15.322886917904777, 49.79735581080685],
      [15.317222092465324, 49.788268849425094],
      [15.30108592303173, 49.78926628214111],
    ],
  ],
};

const saved = await myEntityRepository.save({ geometry: polygon });
console.log(saved.geometry) // Returns hex eg. 0101000020E61000003D0AD7A3703D28409A99999999B94640, i expect exact value polygon declared above

const found = await myEntityRepository.findOne({id: 1});

console.log(found.geometry) // Returns exact value like polygon declared above

My Environment

Dependency Version
Operating System macos
Node.js version v20.12.0
Typescript version 5.4.3
TypeORM version ^0.3.20

Additional Context

I can see from the tests here that typeorm is aware of this https://github.com/typeorm/typeorm/blob/master/test/functional/spatial/postgres/spatial-postgres.ts#L184. As they assign the value to the result of save.

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant