{"id":13483035,"url":"https://github.com/crystal-lang/crystal-db","last_synced_at":"2025-05-16T02:09:22.306Z","repository":{"id":5604137,"uuid":"52573974","full_name":"crystal-lang/crystal-db","owner":"crystal-lang","description":"Common db api for crystal","archived":false,"fork":false,"pushed_at":"2024-11-29T01:47:27.000Z","size":1423,"stargazers_count":304,"open_issues_count":36,"forks_count":56,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-04-08T13:06:49.703Z","etag":null,"topics":["crystal","database"],"latest_commit_sha":null,"homepage":"https://crystal-lang.github.io/crystal-db/api/latest/","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/crystal-lang.png","metadata":{"funding":{"open_collective":"crystal-lang"},"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-02-26T02:54:54.000Z","updated_at":"2025-04-04T02:13:46.000Z","dependencies_parsed_at":"2024-01-23T21:20:30.344Z","dependency_job_id":"0c3402ad-09b1-4e76-add3-a359af42c71d","html_url":"https://github.com/crystal-lang/crystal-db","commit_stats":{"total_commits":235,"total_committers":33,"mean_commits":7.121212121212121,"dds":0.5574468085106383,"last_synced_commit":"023dc5de90c11927656fc747601c5f08ea3c906f"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crystal-lang%2Fcrystal-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crystal-lang%2Fcrystal-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crystal-lang%2Fcrystal-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crystal-lang%2Fcrystal-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crystal-lang","download_url":"https://codeload.github.com/crystal-lang/crystal-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453667,"owners_count":22073618,"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":["crystal","database"],"created_at":"2024-07-31T17:01:07.654Z","updated_at":"2025-05-16T02:09:22.245Z","avatar_url":"https://github.com/crystal-lang.png","language":"Crystal","funding_links":["https://opencollective.com/crystal-lang"],"categories":["Crystal","Database Drivers/Clients"],"sub_categories":[],"readme":"[![Build Status](https://github.com/crystal-lang/crystal-db/workflows/CI/badge.svg)](https://github.com/crystal-lang/crystal-db/actions?query=workflow%3ACI+event%3Apush+branch%3Amaster)\n\n# crystal-db\n\nCommon db api for crystal. You will need to have a specific driver to access a database.\n\n* [SQLite](https://github.com/crystal-lang/crystal-sqlite3)\n* [MySQL](https://github.com/crystal-lang/crystal-mysql)\n* [PostgreSQL](https://github.com/will/crystal-pg)\n* [ODBC](https://github.com/naqvis/crystal-odbc)\n* [Cassandra](https://github.com/kaukas/crystal-cassandra)\n* [DuckDB](https://github.com/amauryt/crystal-duckdb)\n* [Microsoft SQL Server](https://github.com/wonderix/crystal-tds)\n\n## Installation\n\nIf you are creating a shard that will work with _any_ driver, then add `crystal-db` as a dependency in `shard.yml`:\n\n```yaml\ndependencies:\n  db:\n    github: crystal-lang/crystal-db\n```\n\nIf you are creating an application that will work with _some specific_ driver(s), then add them in `shard.yml`:\n\n```yaml\ndependencies:\n  sqlite3:\n    github: crystal-lang/crystal-sqlite3\n```\n\n`crystal-db` itself will be a nested dependency if drivers are included.\n\nNote: Multiple drivers can be included in the same application.\n\n## Documentation\n\n* [Latest API](https://crystal-lang.github.io/crystal-db/api/latest/)\n* [Crystal book](https://crystal-lang.org/docs/database/)\n\n## Usage\n\nThis shard only provides an abstract database API. In order to use it, a specific driver for the intended database has to be required as well:\n\nThe following example uses SQLite where `?` indicates the arguments. If PostgreSQL is used `$1`, `$2`, etc. should be used. `crystal-db` does not interpret the statements.\n\n```crystal\nrequire \"db\"\nrequire \"sqlite3\"\n\nDB.open \"sqlite3:./file.db\" do |db|\n  # When using the pg driver, use $1, $2, etc. instead of ?\n  db.exec \"create table contacts (name text, age integer)\"\n  db.exec \"insert into contacts values (?, ?)\", \"John Doe\", 30\n\n  args = [] of DB::Any\n  args \u003c\u003c \"Sarah\"\n  args \u003c\u003c 33\n  db.exec \"insert into contacts values (?, ?)\", args: args\n\n  puts \"max age:\"\n  puts db.scalar \"select max(age) from contacts\" # =\u003e 33\n\n  puts \"contacts:\"\n  db.query \"select name, age from contacts order by age desc\" do |rs|\n    puts \"#{rs.column_name(0)} (#{rs.column_name(1)})\"\n    # =\u003e name (age)\n    rs.each do\n      puts \"#{rs.read(String)} (#{rs.read(Int32)})\"\n      # =\u003e Sarah (33)\n      # =\u003e John Doe (30)\n    end\n  end\nend\n```\n\n## Roadmap\n\nIssues not yet addressed:\n\n- [x] Support non prepared statements. [#25](https://github.com/crystal-lang/crystal-db/pull/25)\n- [x] Time data type. (implementation details depends on actual drivers)\n- [x] Data type extensibility. Allow each driver to extend the data types allowed.\n- [x] Transactions \u0026 nested transactions. [#27](https://github.com/crystal-lang/crystal-db/pull/27)\n- [x] Connection pool.\n- [x] Logging\n- [ ] Direct access to `IO` to avoid memory allocation for blobs.\n\n## Contributing\n\n1. Fork it ( https://github.com/crystal-lang/crystal-db/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- [bcardiff](https://github.com/bcardiff) Brian J. Cardiff - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrystal-lang%2Fcrystal-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrystal-lang%2Fcrystal-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrystal-lang%2Fcrystal-db/lists"}