{"id":14955592,"url":"https://github.com/cookpad/armg","last_synced_at":"2025-10-13T17:32:41.923Z","repository":{"id":37042961,"uuid":"99908522","full_name":"cookpad/armg","owner":"cookpad","description":"Add MySQL geometry type to Active Record.","archived":false,"fork":false,"pushed_at":"2025-04-07T10:09:15.000Z","size":101,"stargazers_count":19,"open_issues_count":1,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-01T18:38:19.643Z","etag":null,"topics":["activerecord","geometry","hacktoberfest","mysql","rails","rails5","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cookpad.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-08-10T09:55:41.000Z","updated_at":"2025-04-07T10:06:05.000Z","dependencies_parsed_at":"2025-05-25T20:07:04.994Z","dependency_job_id":"9f6393e9-3757-4ea4-a279-1ebadadc1da0","html_url":"https://github.com/cookpad/armg","commit_stats":{"total_commits":105,"total_committers":10,"mean_commits":10.5,"dds":0.5809523809523809,"last_synced_commit":"dbe791295bcc83b7d347fe58d2a41d738fc58e5d"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/cookpad/armg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cookpad%2Farmg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cookpad%2Farmg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cookpad%2Farmg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cookpad%2Farmg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cookpad","download_url":"https://codeload.github.com/cookpad/armg/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cookpad%2Farmg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278772507,"owners_count":26043183,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","geometry","hacktoberfest","mysql","rails","rails5","ruby"],"created_at":"2024-09-24T13:11:25.196Z","updated_at":"2025-10-08T18:04:46.278Z","avatar_url":"https://github.com/cookpad.png","language":"Ruby","readme":"# Armg\n\nAdd MySQL geometry type to Active Record.\n\n[![Gem Version](https://badge.fury.io/rb/armg.svg)](https://badge.fury.io/rb/armg)\n[![Build Status](https://github.com/cookpad/armg/workflows/test/badge.svg?branch=master)](https://github.com/cookpad/armg/actions)\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'armg'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install armg\n\n## Usage\n\n```ruby\nrequire 'active_record'\nrequire 'armg'\n\nActiveRecord::Base.establish_connection(adapter: 'mysql2', database: 'my_db')\n\nActiveRecord::Migration.create_table :geoms, options: 'ENGINE=MyISAM' do |t|\n  t.geometry 'location', null: false\n  t.index ['location'], name: 'idx_location', type: :spatial\nend\n\nclass Geom \u003c ActiveRecord::Base; end\n\nwkt_parser = RGeo::WKRep::WKTParser.new(nil, support_ewkt: true)\npoint = wkt_parser.parse('SRID=4326;Point(-122.1 47.3)')\nGeom.create!(location: point)\n\nGeom.first\n#=\u003e #\u003cGeom id: 1, location: #\u003cRGeo::Cartesian::PointImpl:0x... \"POINT (-122.1 47.3)\"\u003e\u003e\n```\n\n## Using WKT\n\n```ruby\nArmg.deserializer = Armg::WktDeserializer.new\nArmg.serializer = Armg::WktSerializer.new\n\nGeom.create!(location: 'Point(-122.1 47.3)')\n\nGeom.first\n#=\u003e #\u003cGeom id: 1, location: \"Point (-122.1 47.3)\"\u003e\n```\n\n## Using custom deserializer\n\n```ruby\nclass CustomDeserializer\n  def initialize\n    factory = RGeo::Geographic.spherical_factory(srid: 0)\n    @wkb_parser = RGeo::WKRep::WKBParser.new(factory, support_ewkb: true)\n  end\n\n  def deserialize(wkb)\n    wkb_without_srid = wkb.b.slice(4..-1)\n    @wkb_parser.parse(wkb_without_srid)\n  end\nend\n\nArmg.deserializer = CustomDeserializer.new\n\nGeom.take\n#=\u003e #\u003cGeom id: 1, location: #\u003cRGeo::Geographic::SphericalPointImpl:0x... \"POINT (-122.1 47.3)\"\u003e\u003e\n```\n\n## Using custom serializer\n\n```ruby\nclass CustomSerializer\n  def initialize\n    @wkt_parser = RGeo::WKRep::WKTParser.new(nil, support_ewkt: true)\n    @wkb_generator = RGeo::WKRep::WKBGenerator.new(type_format: :ewkb, little_endian: true)\n  end\n\n  def serialize(value)\n    if value.is_a?(String)\n      value = @wkt_parser.parse(value)\n    end\n\n    srid = \"\\x00\\x00\\x00\\x00\"\n    srid + @wkb_generator.generate(value)\n  end\nend\n\nArmg.serializer = CustomSerializer.new\n\nGeom.create!(id: 4, location: 'Point(-122.1 47.3)')\n```\n\n## Running tests\n\n```sh\ndocker-compose up -d\nbundle install\nbundle exec appraisal install\nbundle exec appraisal ar61 rake\n# bundle exec appraisal ar60 rake\n# ARMG_TEST_MYSQL_PORT=10057 bundle exec appraisal ar61 rake # MySQL 5.7\n# ARMG_TEST_MYSQL_PORT=10057 ARMG_TEST_MYSQL_ENGINE=InnoDB bundle exec appraisal ar61 rake\n```\n\n## Using with [Ridgepole](https://github.com/winebarrel/ridgepole)\n\nYou need to extend the TableDefinition class.\n\n```ruby\n# ridgepole-geo.rb\nmodule TableDefinitionExtForGeometry\n  def geometry(*args)\n    options = args.extract_options!\n    column_names = args\n    column_names.each { |name| column(name, :geometry, options) }\n  end\nend\nRidgepole::DSLParser::TableDefinition.prepend(TableDefinitionExtForGeometry)\n\nmodule DiffExtForGeometry\n  def normalize_index_options!(opts)\n    super\n    opts.delete(:length) if opts[:type] == :spatial\n  end\nend\nRidgepole::Diff.prepend(DiffExtForGeometry)\n```\n\n```sh\n$ ridgepole -c 'mysql2://root@127.0.0.1:10057/armg_test' -r armg -e \u003e Schemafile\n\n$ cat Schemafile\n# Export Schema\ncreate_table \"geoms\", options: \"ENGINE=InnoDB DEFAULT CHARSET=utf8\", force: :cascade do |t|\n  t.geometry \"location\", null: false\n  t.string \"name\"\n  t.index [\"location\"], name: \"idx_location\", length: 32, type: :spatial\n  t.index [\"name\"], name: \"idx_name\", length: 10\nend\n\n$ ridgepole -c 'mysql2://root@127.0.0.1:10057/armg_test' -r armg,ridgepole-geo -a\nApply `Schemafile`\nNo change\n```\n\n## Supported versions\n\n- Ruby 3.1 to 3.4\n- ActiveRecord 7.0 to 8.0\n- MySQL 5.6 to 8.0\n\n### Limitation on MySQL 8.0\n\nAt the moment, armg gem supports only SRIDs with long-lat axis order in MySQL 8.0.\ne.g. SRID=3857 (WGS 84 / Pseudo-Mercator -- Spherical Mercator, Google Maps, OpenStreetMap, Bing, ArcGIS, ESRI)\n\nThat is, armg does not support SRIDs with lat-long axis order.\ne.g. SRID=4326 (WGS 84 -- WGS84 - World Geodetic System 1984, used in GPS)\n\n## Related links\n\n* [rgeo/rgeo: Geospatial data library for Ruby](https://github.com/rgeo/rgeo)\n* [MySQL :: MySQL 5.7 Reference Manual :: 11.5.3 Supported Spatial Data Formats](https://dev.mysql.com/doc/refman/5.7/en/gis-data-formats.html)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcookpad%2Farmg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcookpad%2Farmg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcookpad%2Farmg/lists"}