{"id":44621224,"url":"https://github.com/yancya/relationizer","last_synced_at":"2026-02-14T14:11:41.357Z","repository":{"id":56891674,"uuid":"67765556","full_name":"yancya/relationizer","owner":"yancya","description":"Relationizer create evaluatable string as SQL","archived":false,"fork":false,"pushed_at":"2026-02-12T20:10:37.000Z","size":38,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-02-13T03:35:17.963Z","etag":null,"topics":["sql"],"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/yancya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-09T04:24:45.000Z","updated_at":"2026-02-12T20:10:49.000Z","dependencies_parsed_at":"2022-08-21T01:20:09.306Z","dependency_job_id":null,"html_url":"https://github.com/yancya/relationizer","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/yancya/relationizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yancya%2Frelationizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yancya%2Frelationizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yancya%2Frelationizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yancya%2Frelationizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yancya","download_url":"https://codeload.github.com/yancya/relationizer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yancya%2Frelationizer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29446541,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T14:10:32.461Z","status":"ssl_error","status_checked_at":"2026-02-14T14:09:49.945Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["sql"],"created_at":"2026-02-14T14:11:40.828Z","updated_at":"2026-02-14T14:11:41.352Z","avatar_url":"https://github.com/yancya.png","language":"Ruby","readme":"# Relationizer\n\nA Ruby gem that converts `Array\u003cArray\u003e` into SQL relation literals. Supports BigQuery and PostgreSQL.\n\n## Installation\n\n```ruby\ngem 'relationizer'\n```\n\n```\n$ bundle install\n```\n\n## Usage\n\n`include` the backend module you need and call `create_relation_literal(schema, tuples)`.\n\n- `schema` — A Hash of column names to types. Set the value to `nil` to auto-infer the type from the tuples.\n- `tuples` — Row data as `Array\u003cArray\u003e`.\n\n### BigQuery\n\n```ruby\nrequire 'relationizer/big_query'\n\nclass MyQuery\n  include Relationizer::BigQuery\nend\n\nq = MyQuery.new\n\nq.create_relation_literal(\n  { id: nil, name: nil },\n  [[1, 'hoge'], [2, 'fuga']]\n)\n#=\u003e \"SELECT * FROM UNNEST(ARRAY\u003cSTRUCT\u003c`id` INT64, `name` STRING\u003e\u003e[(1, 'hoge'), (2, 'fuga')])\"\n```\n\n#### Auto type inference\n\n| Ruby type             | BigQuery type |\n|-----------------------|---------------|\n| `Integer`             | INT64         |\n| `Float` / `BigDecimal` | FLOAT64     |\n| `String`              | STRING        |\n| `TrueClass` / `FalseClass` | BOOL    |\n| `Time` / `DateTime`   | TIMESTAMP    |\n| `Date`                | DATE          |\n| `Array`               | ARRAY\u003cT\u003e     |\n\n#### Manual type specification\n\nPass a Symbol as the schema value to override auto-inference. Useful when a column contains mixed types or when tuples are empty.\n\n```ruby\n# Force ratio column to FLOAT64 (mixed Integer and Float)\nq.create_relation_literal(\n  { id: nil, ratio: :FLOAT64 },\n  [[1, 1], [2, 3.14]]\n)\n#=\u003e \"SELECT * FROM UNNEST(ARRAY\u003cSTRUCT\u003c`id` INT64, `ratio` FLOAT64\u003e\u003e[(1, 1), (2, 3.14)])\"\n\n# Empty tuples (manual type specification is required)\nq.create_relation_literal(\n  { id: :INT64, name: :STRING },\n  []\n)\n#=\u003e \"SELECT * FROM UNNEST(ARRAY\u003cSTRUCT\u003c`id` INT64, `name` STRING\u003e\u003e[])\"\n```\n\n#### Array columns\n\n```ruby\nq.create_relation_literal(\n  { id: nil, name: nil, combination: nil },\n  [[1, 'hoge', [1, 2, 3]], [2, 'fuga', [4, 5, 6]]]\n)\n#=\u003e \"SELECT * FROM UNNEST(ARRAY\u003cSTRUCT\u003c`id` INT64, `name` STRING, `combination` ARRAY\u003cINT64\u003e\u003e\u003e[(1, 'hoge', [1, 2, 3]), (2, 'fuga', [4, 5, 6])])\"\n```\n\n#### Single column\n\nBigQuery does not support single-column STRUCTs in UNNEST, so a dummy column is added internally. Only the original column is returned in the SELECT.\n\n```ruby\nq.create_relation_literal(\n  { id: nil },\n  [[1], [2], [3]]\n)\n#=\u003e \"SELECT id FROM UNNEST(ARRAY\u003cSTRUCT\u003c`id` INT64, `___dummy` STRING\u003e\u003e[(1, NULL), (2, NULL), (3, NULL)])\"\n```\n\n### PostgreSQL\n\n```ruby\nrequire 'relationizer/postgresql'\n\nclass MyQuery\n  include Relationizer::Postgresql\nend\n\nq = MyQuery.new\n\nq.create_relation_literal(\n  { id: nil, name: nil },\n  [[1, 'hoge'], [2, 'fuga']]\n)\n#=\u003e %Q{SELECT \"id\"::INT8, \"name\"::TEXT FROM (VALUES('1', 'hoge'), ('2', 'fuga')) AS t(\"id\", \"name\")}\n```\n\n#### Auto type inference\n\n| Ruby type             | PostgreSQL type |\n|-----------------------|-----------------|\n| `Integer`             | INT8            |\n| `Float`               | FLOAT8          |\n| `BigDecimal`          | DECIMAL         |\n| `String`              | TEXT            |\n| `TrueClass` / `FalseClass` | BOOLEAN   |\n| `Time` / `DateTime`   | TIMESTAMPTZ    |\n| `Date`                | DATE            |\n\n#### NULL\n\n`nil` values are converted to SQL `NULL`.\n\n```ruby\nq.create_relation_literal(\n  { id: nil },\n  [[1], [nil]]\n)\n#=\u003e %Q{SELECT \"id\"::INT8 FROM (VALUES('1'), (NULL)) AS t(\"id\")}\n```\n\n## Errors\n\n- `ReasonlessTypeError` — Raised when types are mixed within a single column (e.g. Integer and String in the same column)\n- `TypeNotFoundError` (BigQuery only) — Raised when tuples are empty and types are not manually specified\n\n## License\n\n[MIT License](http://opensource.org/licenses/MIT)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyancya%2Frelationizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyancya%2Frelationizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyancya%2Frelationizer/lists"}