mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
1 line
202 KiB
JavaScript
1 line
202 KiB
JavaScript
|
crystal_doc_search_index_callback({"repository_name":"db","body":"[![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\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](http://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 << \"Sarah\"\n args << 33\n db.exec \"insert into contacts values (?, ?)\", args: args\n\n puts \"max age:\"\n puts db.scalar \"select max(age) from contacts\" # => 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 # => name (age)\n rs.each do\n puts \"#{rs.read(String)} (#{rs.read(Int32)})\"\n # => Sarah (33)\n # => 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 & 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","program":{"html_id":"db/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"ancestors":[{"html_id":"db/Spec/Methods","kind":"module","full_name":"Spec::Methods","name":"Methods"},{"html_id":"db/Spec/Expectations","kind":"module","full_name":"Spec::Expectations","name":"Expectations"}],"locations":[],"repository_name":"db","program":true,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/Spec/Expectations","kind":"module","full_name":"Spec::Expectations","name":"Expectations"},{"html_id":"db/Spec/Methods","kind":"module","full_name":"Spec::Methods","name":"Methods"}],"extended_modul
|