{"id":13483780,"url":"https://github.com/topaz-crystal/topaz","last_synced_at":"2025-04-14T19:36:34.927Z","repository":{"id":75519297,"uuid":"74814837","full_name":"topaz-crystal/topaz","owner":"topaz-crystal","description":"A simple and useful db wrapper for Crystal-lang","archived":false,"fork":false,"pushed_at":"2017-09-16T19:38:11.000Z","size":129,"stargazers_count":59,"open_issues_count":2,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T08:01:46.565Z","etag":null,"topics":["activerecord","crystal","database","db","db-wrapper","model","orm","orm-library","topaz"],"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/topaz-crystal.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}},"created_at":"2016-11-26T08:51:46.000Z","updated_at":"2024-05-31T11:55:02.000Z","dependencies_parsed_at":"2023-06-06T18:15:19.783Z","dependency_job_id":null,"html_url":"https://github.com/topaz-crystal/topaz","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topaz-crystal%2Ftopaz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topaz-crystal%2Ftopaz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topaz-crystal%2Ftopaz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topaz-crystal%2Ftopaz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/topaz-crystal","download_url":"https://codeload.github.com/topaz-crystal/topaz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248946878,"owners_count":21187588,"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":["activerecord","crystal","database","db","db-wrapper","model","orm","orm-library","topaz"],"created_at":"2024-07-31T17:01:15.208Z","updated_at":"2025-04-14T19:36:34.898Z","avatar_url":"https://github.com/topaz-crystal.png","language":"Crystal","funding_links":[],"categories":["ORM/ODM Extensions"],"sub_categories":[],"readme":"\u003cimg src=\"https://cloud.githubusercontent.com/assets/3483230/20856901/fad1885e-b95f-11e6-848d-c46e33d8290e.png\" width=\"100px\"/\u003e\n\n# Topaz [![Build Status](https://travis-ci.org/topaz-crystal/topaz.svg?branch=master)](https://travis-ci.org/topaz-crystal/topaz) [![GitHub release](https://img.shields.io/github/release/topaz-crystal/topaz.svg)]()\n[![Dependency Status](https://shards.rocks/badge/github/topaz-crystal/topaz/status.svg)](https://shards.rocks/github/topaz-crystal/topaz)\n[![devDependency Status](https://shards.rocks/badge/github/topaz-crystal/topaz/dev_status.svg)](https://shards.rocks/github/topaz-crystal/topaz)\n\nTopaz is a simple and useful db wrapper for crystal lang.\nTopaz is inspired by active record design pattern, but not fully implemented.\nSee [sample code](https://github.com/topaz-crystal/topaz/blob/master/samples) for detail.\n[Here](https://github.com/topaz-crystal/topaz-kemal-sample) is another sample that shows how Topaz works in Kemal.  \nDepends on [crystal-lang/crystal-mysql](https://github.com/crystal-lang/crystal-mysql), [crystal-lang/crystal-sqlite3](https://github.com/crystal-lang/crystal-sqlite3) and [crystal-pg](https://github.com/will/crystal-pg)\n\n## Usage\n\n**1. Setup DB**\n```crystal\nTopaz::Db.setup(\"mysql://root@localhost/topaz\") # For MySQL\nTopaz::Db.setup(\"postgres://root@localhost/topaz\") # For PostgreSQL\nTopaz::Db.setup(\"sqlite3://./db/data.db\") # For SQLite3\n```\n\n**2. Define models**\n```crystal\nclass SampleModel \u003c Topaz::Model\n  columns(\n    name: String\n  )\nend\n\n# You can drop or create a table\nSampleModel.create_table\nSampleModel.drop_table\n```\n\n**3. Create, find, update and delete models**\n```crystal\ns = SampleModel.create(\"Sample Name\")\n\nSampleModel.find(1).name\n# =\u003e \"Sample Name\"\nSampleModel.where(\"name = 'Sample Name'\").size\n# =\u003e 1\n```\nSee [sample code](https://github.com/topaz-crystal/topaz/blob/master/samples/model.cr) for detail.\n\n**4. Define associations between models**\n```crystal\nrequire \"topaz\"\n\nclass SampleParent \u003c Topaz::Model\n  columns # Empty columns\n  has_many(children: {model: SampleChild, key: parent_id})\nend\n\nclass SampleChild \u003c Topaz::Model\n  columns( # Define foreign key\n    parent_id: Int32\n  )\n  belongs_to(parent: {model: SampleParent, key: parent_id})\nend\n\np = SampleParent.create\n\nchild1 = SampleChild.create(p.id)\nchild2 = SampleChild.create(p.id)\nchild3 = SampleChild.create(p.id)\n\np.children.size\n# =\u003e 3\n\nchild1.parent.id\n# =\u003e 1\n```\nSee [sample code](https://github.com/topaz-crystal/topaz/blob/master/samples/association.cr) for detail.  \n\n**Other features**\n* Transaction\n* Table migration\n* `Model#to_json` and `Model#from_json`\n* `created_at` and `updated_at` column\n* Nullable column\n* Column with default value\n* Change id from Int32 to Int64\n\nSee [sample codes](https://github.com/topaz-crystal/topaz/tree/master/samples) for detail.\n\n**Supported data types.**  \nString, Int32, Int64, Float32, Float64\n\n## Development\n\nSetting up PostgreSQL:\n\n```\n$ psql\n  # CREATE USER root WITH CREATEDB;\n  # CREATE DATABASE topaz_test WITH OWNER = root;\n```\n\nSetting up MySQL:\n\n```\n$ mysql -u root\nmysql\u003e create database topaz_test;\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/topaz-crystal/topaz/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- [tbrand](https://github.com/tbrand) Taichiro Suzuki - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftopaz-crystal%2Ftopaz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftopaz-crystal%2Ftopaz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftopaz-crystal%2Ftopaz/lists"}