{"id":18473500,"url":"https://github.com/werner/bones","last_synced_at":"2025-08-24T12:34:06.788Z","repository":{"id":143392298,"uuid":"129399471","full_name":"werner/bones","owner":"werner","description":"SQL Query Builder for Crystal","archived":false,"fork":false,"pushed_at":"2018-04-19T20:31:20.000Z","size":84,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-13T13:04:07.644Z","etag":null,"topics":["crystal","dsl","query-builder","sql"],"latest_commit_sha":null,"homepage":"","language":"Crystal","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/werner.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-13T12:29:38.000Z","updated_at":"2018-11-04T12:17:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"6dd0597b-7f84-4e9d-98ca-886f69957381","html_url":"https://github.com/werner/bones","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/werner/bones","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/werner%2Fbones","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/werner%2Fbones/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/werner%2Fbones/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/werner%2Fbones/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/werner","download_url":"https://codeload.github.com/werner/bones/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/werner%2Fbones/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271863676,"owners_count":24835839,"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-08-24T02:00:11.135Z","response_time":111,"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":["crystal","dsl","query-builder","sql"],"created_at":"2024-11-06T10:25:17.997Z","updated_at":"2025-08-24T12:34:06.766Z","avatar_url":"https://github.com/werner.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bones [![Build Status](https://travis-ci.org/werner/bones.png)](https://travis-ci.org/werner/bones)\n\nA SQL Query Builder for Crystal.\n\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  bones:\n    github: werner/bones\n```\n\n## Usage\n\n```crystal\nrequire \"bones\"\n\nclass Person \u003c Bones::TableDef\n  table_name person\n  column id : Int32\n  column age : Int32\n  column name : String\n  column gender : Char\n\n  has_many :worker\n  has_many :position\n  has_many :vehicle\n  has_many :department\nend\n\nclass Worker \u003c Bones::TableDef\n  table_name worker\n  column id : Int32\n  column person_id : Int32\n  column name : String\n\n  belongs_to :person\nend\n\nclass Position \u003c Bones::TableDef\n  table_name position\n  column id : Int32\n  column person_id : Int32\n  column name : String\n\n  belongs_to :person\nend\n\nclass Vehicle \u003c Bones::TableDef\n  table_name vehicle\n  column id : Int32\n  column person_id : Int32\n  column name : String\n\n  belongs_to :person\nend\n\nclass Department \u003c Bones::TableDef\n  table_name department\n  column id : Int32\n  column person_id : Int32\n  column name : String\n\n  belongs_to :person\nend\n\nperson = Person.new\nworker = Worker.new\nposition = Position.new\nvehicle = Vehicle.new\ndepartment = Department.new\n\nperson_id = person.id\nworker_id = worker.id\nposition_id = position.id\nworker_person_id = worker.person_id\nposition_person_id = position.person_id \nvehicle_person_id = vehicle.person_id\ndepartment_person_id = department.person_id\n\nperson_age = person.age\nperson_name = person.name\nworker_name = worker.name\ndepartment_name = department.name\nperson_gender = person.gender\n\nsql = Bones::SQL::SQL.new\nsql.select(person_id, person_name, worker_name, sql.sum(person_age))\n  .from(person)\n  .inner_join(to_table: worker, on: person_id.dup.eq(worker_person_id))\n  .inner_join(to_table: position, on: person_id.dup.eq(position_person_id))\n  .left_join(to_table: vehicle, on: person_id.dup.eq(vehicle_person_id))\n  .right_join(to_table: department, on: person_id.dup.eq(department_person_id))\n  .where(worker_name.eq(\"Jhon\").and(person_gender.eq('M')).or(person_age.gt(20)).and(person_id.is_not(nil)))\n  .order_by(person_id.asc)\n  .group_by(person_id, person_name, worker_name)\n  .having(sql.sum(person_age).lt(100).and(sql.count(person_id).gt(1)))\n  .limit(100)\n  .offset(2)\n  .to_sql_string\n\n# SELECT person.id, person.name, worker.name, SUM(person.age) FROM person INNER JOIN worker ON person.id = worker.person_id \n# INNER JOIN position ON person.id = position.person_id\n# LEFT JOIN vehicle ON person.id = vehicle.person_id\n# RIGHT JOIN department ON person.id = department.person_id\n# WHERE worker.name = 'Jhon' AND person.gender = 'M' OR person.age \u003e 20\n# AND person.id IS NOT NULL\n# GROUP BY person.id, person.name, worker.name\n# HAVING SUM(person.age) \u003c 100 AND COUNT(person.id) \u003e 1\n# ORDER BY person.id ASC\n# LIMIT 100 OFFSET 2\n\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/werner/bones/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create a new Pull Request\n\n## Contributors\n\n- [werner](https://github.com/werner) werner - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwerner%2Fbones","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwerner%2Fbones","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwerner%2Fbones/lists"}