Skip to content

GeomFromText in MySQL changed to ST_GeomFromText #9786

Closed

Description

@tschams

What are you doing?

inserting into mysql db a geometry point

const shulInfo = { ...req.body };
    shulInfo.location_point = {
        type: 'Point',
        coordinates: [shulInfo.location.lat, shulInfo.location.lng]
    };
    minyan_locations.create(shulInfo);
  })

What do you expect to happen?

I wanted to insert

What is actually happening?

Unhandled rejection SequelizeDatabaseError: FUNCTION godaven.GeomFromText does not exist
at Query.formatError (C:\projects\website\node_modules\sequelize\lib\dialects\mysql\query.js:247:16)
Output, either JSON or SQL

Dialect: mysql
__Dialect version:latest available
__Database version:latest available
__Sequelize version:latest available
__Tested with latest release:latest available

It worked when I changed your datatypes.js file to the following:
GEOMETRY.prototype._stringify = function _stringify(value, options) {
return 'ST_GeomFromText(' + options.escape(Wkt.convert(value)) + ')';
};

Previously it was "GeomFromText", I changed it to "ST_GeomFromText".
My reasoning was because MySQL now changed its syntax to "ST_GeomFromText".

Activity

  1. sushantdhiman commented on Aug 15, 2018

    @sushantdhiman
    Contributor

    These functions are removed in favor of the ST_ names:

    https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-0.html

    Looks like we need to change this function based on database version.

  2. added
    type: bug
    dependency
    dialect: mysql
    on Aug 15, 2018
  3. sansuba commented on Sep 10, 2018

    @sansuba

    How I can use update query with GIS update with ST_ GeomFromText rather than existing ORM support GeomFromText ? Please can help anyone regarding to this case ?

    Currently it gives me this error
    Unhandled rejection SequelizeDatabaseError: FUNCTION db.GeomFromText does not exist

    I have updated the ORM and MySQL version to Ver 8.0.12
    has anyone with solution ?

  4. maluramichael commented on Sep 17, 2018

    @maluramichael

    I have this problem too right
    sequelize 4.38.0
    mysql Ver 8.0.12 for osx10.13 on x86_64 (Homebrew)

    Is there any workaround for this?

  5. whittakergroupinc commented on Nov 9, 2018

    @whittakergroupinc

    I found this to work:
    In this file: node_modules/sequelize/lib/data-types.js
    On lines 708 and 726 change GeomFromText --> ST_GeomFromText

  6. MunifTanjim commented on Dec 15, 2018

    @MunifTanjim

    Until this get's resolved:

    const Sequelize = require('sequelize')
    
    const Wkt = require('terraformer-wkt-parser')
    Sequelize.GEOMETRY.prototype._stringify = function _stringify(value, options) {
      return 'ST_GeomFromText(' + options.escape(Wkt.convert(value)) + ')'
    }
    Sequelize.GEOGRAPHY.prototype._stringify = function _stringify(value, options) {
      return 'ST_GeomFromText(' + options.escape(Wkt.convert(value)) + ')'
    }
    
    const sequelize = new Sequelize()

    Idea from @whittakergroupinc

  7. dragondgold commented on Mar 18, 2019

    @dragondgold

    Until this get's resolved:

    const Sequelize = require('sequelize')
    
    const Wkt = require('terraformer-wkt-parser')
    Sequelize.GEOMETRY.prototype._stringify = function _stringify(value, options) {
      return 'ST_GeomFromText(' + options.escape(Wkt.convert(value)) + ')'
    }
    Sequelize.GEOGRAPHY.prototype._stringify = function _stringify(value, options) {
      return 'ST_GeomFromText(' + options.escape(Wkt.convert(value)) + ')'
    }
    
    const sequelize = new Sequelize()

    Idea from @whittakergroupinc

    This doesn't work anymore with sequelize v5, any workaround for this in v5?

  8. MunifTanjim commented on Mar 18, 2019

    @MunifTanjim

    Probably this:

    const Sequelize = require('sequelize')
    
    const wkx = require('wkx')
    Sequelize.GEOMETRY.prototype._stringify = function _stringify(value, options) {
      return `ST_GeomFromText(${options.escape(wkx.Geometry.parseGeoJSON(value).toWkt())})`;
    }
    Sequelize.GEOMETRY.prototype._bindParam = function _bindParam(value, options) {
      return `ST_GeomFromText(${options.bindParam(wkx.Geometry.parseGeoJSON(value).toWkt())})`;
    }
    Sequelize.GEOGRAPHY.prototype._stringify = function _stringify(value, options) {
      return `ST_GeomFromText(${options.escape(wkx.Geometry.parseGeoJSON(value).toWkt())})`;
    }
    Sequelize.GEOGRAPHY.prototype._bindParam = function _bindParam(value, options) {
      return `ST_GeomFromText(${options.bindParam(wkx.Geometry.parseGeoJSON(value).toWkt())})`;
    }
    
    const sequelize = new Sequelize()
  9. added
    existing workaround
    status: understood
    and removed
    dependency
    on Jul 24, 2019
  10. goalia commented on Nov 1, 2019

    @goalia

    +1 I've the same issue today. I fix the problem with @MunifTanjim proposition. Can you integrate this fix in new release ? I can help if it's necessary :)

  11. papb commented on Nov 2, 2019

    @papb
    Member

    Hi everyone! This seems related to the v8 release of MySQL, can anyone confirm? If we make this change, would it break for <v8 users?

  12. 3 remaining items

  13. added 2 commits that reference this issue on Jul 2, 2020
    d4e8f0e
    ff2af57
  14. maulikpatel-in commented on Nov 1, 2020

    @maulikpatel-in

    Face the same issue with sequelize 6.3.x, and @MunifTanjim solution was worked for me.

  15. blankstar85 commented on Nov 2, 2020

    @blankstar85

    Are you using typescript? maybe I didn't spend enough time, but its not working for me. any suggestions?

  16. MunifTanjim commented on Nov 2, 2020

    @MunifTanjim

    its not working for me. any suggestions?

    Why so? Nobody can give you any suggestions if you don't share enough information. Which TypeScript version are you using? Which Sequelize version? MySQL version? What are the errors? What are the warnings? What are you trying?

    @blankstar85

  17. blankstar85 commented on Nov 2, 2020

    @blankstar85

    @MunifTanjim Thanks for the quick reply.
    I'm using:
    typescript: 3.9.7
    sequelize: 5.22.3
    sequelize-typescript: 1.1.0
    Mysql: 8.0

    I just retired to get the error and it works. Sorry I wasted your time, I'm not sure what I did differently. Maybe my installed node packages were all mixed up. Thanks!

  18. NoufalBhai commented on Feb 8, 2021

    @NoufalBhai

    Is this fixed?
    I'm still getting the same issue.

  19. hengki01 commented on Feb 16, 2021

    @hengki01

    Hi everyone! This seems related to the v8 release of MySQL, can anyone confirm? If we make this change, would it break for <v8 users?

    ST_GeomFromText was introduced in MySQL v5.6
    GeomFromText was deprecated from MySQL v5.7.6

    Probably this:

    const Sequelize = require('sequelize')
    
    const wkx = require('wkx')
    Sequelize.GEOMETRY.prototype._stringify = function _stringify(value, options) {
      return `ST_GeomFromText(${options.escape(wkx.Geometry.parseGeoJSON(value).toWkt())})`;
    }
    Sequelize.GEOMETRY.prototype._bindParam = function _bindParam(value, options) {
      return `ST_GeomFromText(${options.bindParam(wkx.Geometry.parseGeoJSON(value).toWkt())})`;
    }
    Sequelize.GEOGRAPHY.prototype._stringify = function _stringify(value, options) {
      return `ST_GeomFromText(${options.escape(wkx.Geometry.parseGeoJSON(value).toWkt())})`;
    }
    Sequelize.GEOGRAPHY.prototype._bindParam = function _bindParam(value, options) {
      return `ST_GeomFromText(${options.bindParam(wkx.Geometry.parseGeoJSON(value).toWkt())})`;
    }
    
    const sequelize = new Sequelize()

    It's almost 2 years and still works !

  20. Hwan-seok commented on Apr 20, 2021

    @Hwan-seok

    Why is this not being fixed?

  21. neel2902 commented on Apr 21, 2021

    @neel2902

    I am using

    • mysql: 8.0.23
    • sequelize: 6.6.2

    In node_modules/sequelize/lib/data-types.js
    In line 847 and 850, changing GeomFromText to ST_GeomFromText did the job for me.

  22. added a commit that references this issue on Oct 4, 2021
  23. added a commit that references this issue on Oct 24, 2021
    85bfab8
  24. sgambolati-ua commented on May 9, 2023

    @sgambolati-ua

    I am using

    • mysql: 8.0.23
    • sequelize: 6.6.2

    In node_modules/sequelize/lib/data-types.js In line 847 and 850, changing GeomFromText to ST_GeomFromText did the job for me.

    This works for me. Thanks!
    Is there a better way to overload/extend a data type?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    dialect: mysqlexisting workaroundstatus: understoodtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions