{"id":28119439,"url":"https://github.com/puzzleflow/activerecord-postgres-composite-types","last_synced_at":"2025-07-07T19:40:30.922Z","repository":{"id":19880905,"uuid":"23145074","full_name":"PuzzleFlow/activerecord-postgres-composite-types","owner":"PuzzleFlow","description":"This gem adds support for the postgres custom types.","archived":false,"fork":false,"pushed_at":"2016-07-12T20:16:34.000Z","size":71,"stargazers_count":10,"open_issues_count":1,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-23T15:05:03.411Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/PuzzleFlow.png","metadata":{"files":{"readme":"README.rdoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-20T10:37:30.000Z","updated_at":"2021-10-19T18:17:57.000Z","dependencies_parsed_at":"2022-07-23T14:04:29.568Z","dependency_job_id":null,"html_url":"https://github.com/PuzzleFlow/activerecord-postgres-composite-types","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/PuzzleFlow/activerecord-postgres-composite-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PuzzleFlow%2Factiverecord-postgres-composite-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PuzzleFlow%2Factiverecord-postgres-composite-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PuzzleFlow%2Factiverecord-postgres-composite-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PuzzleFlow%2Factiverecord-postgres-composite-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PuzzleFlow","download_url":"https://codeload.github.com/PuzzleFlow/activerecord-postgres-composite-types/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PuzzleFlow%2Factiverecord-postgres-composite-types/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264139552,"owners_count":23563245,"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","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":[],"created_at":"2025-05-14T07:18:07.075Z","updated_at":"2025-07-07T19:40:30.916Z","avatar_url":"https://github.com/PuzzleFlow.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿{\u003cimg src=\"https://codeclimate.com/github/PuzzleFlow/activerecord-postgres-composite-types/badges/gpa.svg\" /\u003e}[https://codeclimate.com/github/PuzzleFlow/activerecord-postgres-composite-types]\n{\u003cimg src=\"https://travis-ci.org/PuzzleFlow/activerecord-postgres-composite-types.svg?branch=master\" alt=\"Build Status\" /\u003e}[https://travis-ci.org/PuzzleFlow/activerecord-postgres-composite-types]\n{\u003cimg src=\"http://inch-ci.org/github/PuzzleFlow/activerecord-postgres-composite-types.png?branch=master\" alt=\"Inline docs\" /\u003e}[http://inch-ci.org/github/PuzzleFlow/activerecord-postgres-composite-types]\n{\u003cimg src=\"https://badge.fury.io/rb/activerecord-postgres-composite-types.svg\" alt=\"Gem Version\" /\u003e}[http://badge.fury.io/rb/activerecord-postgres-composite-types]\n\n= ActiveRecord PostgreSQL Composite Types\n\nThis gem adds support to the ActiveRecord (3.x and 4.x) for composite types.\n\nOne of PostgreSQL interesting feature is composite types — it basically allows to group related columns into a single type declaration like this:\n\n  create type complex as (\n    number real,\n    title text\n  );\n\nForm this moment a type 'complex' is a regular PostgreSQL type and can be used in functions, column definitions, other types definition, etc.\nActiveRecord, especially from version 4.0, has extended set of supported types like arrays, hstore, json, range, ...\nBut there is no support for user defined composite types.\n\n== The Goal\n\nI would like to be able to access data from table like this:\n\n  create_table :foos, :id =\u003e false do |t|\n    t.column :comp, :complex, default: \"(0,\\\"\\\")\"\n  end\n\nin simple and natural way using ActiveRecord model:\n\n  class Foo \u003c ActiveRecord::Base\n  end\n\n  foo = Foo.create!(:comp =\u003e {:number =\u003e 1.2, :title =\u003e \"Cool!\"})\n\nor\n\n  foo = Foo.create!(:comp =\u003e [1.2, \"Cool!\"])\n\nand then\n\n  foo.comp.number # =\u003e 1.2\n  foo.comp.title # =\u003e \"Cool!\"\n\nTo achieve this goal I only have to define composite type class in a following way:\n\n  require 'postgres_composite_type'\n  class ComplexType \u003c PostgresCompositeType\n    register_type :complex\n  end\n\nThis class must be loaded before any ActiveRecord model is instantializated, but NOT before\nActiveRecord is loaded. Load your classes with ActiveRecord hook:\n\n  ActiveSupport.on_load :active_record do\n    require 'complex_type'\n  end\n\nYou can of course put this code in your railtie initializer:\n\n  initialize :complexy_type do\n    ActiveSupport.on_load :active_record do\n      require 'complex_type'\n    end\n  end\n\nThat's all folks.\n\n== Contributing to ActiveRecord PostgreSQL Composite Types\n \n* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.\n* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.\n* Fork the project.\n* Start a feature/bugfix branch.\n* Commit and push until you are happy with your contribution.\n* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.\n* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.\n\n== Copyright\n\nCopyright (c) 2014 PuzzleFlow. See LICENSE for further details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuzzleflow%2Factiverecord-postgres-composite-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuzzleflow%2Factiverecord-postgres-composite-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuzzleflow%2Factiverecord-postgres-composite-types/lists"}