{"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* [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 << \"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_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"}],"types":[{"html_id":"db/DB","path":"DB.html","kind":"module","full_name":"DB","name":"DB","abstract":false,"locations":[{"filename":"src/db.cr","line_number":82,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L82"},{"filename":"src/db/begin_transaction.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/begin_transaction.cr#L1"},{"filename":"src/db/connection.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L1"},{"filename":"src/db/connection_builder.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection_builder.cr#L1"},{"filename":"src/db/connection_context.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection_context.cr#L1"},{"filename":"src/db/database.cr","line_number":4,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/database.cr#L4"},{"filename":"src/db/disposable.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/disposable.cr#L1"},{"filename":"src/db/driver.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/driver.cr#L1"},{"filename":"src/db/enumerable_concat.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/enumerable_concat.cr#L1"},{"filename":"src/db/error.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L1"},{"filename":"src/db/mapping.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/mapping.cr#L1"},{"filename":"src/db/pool.cr","line_number":5,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L5"},{"filename":"src/db/pool_prepared_statement.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_prepared_statement.cr#L1"},{"filename":"src/db/pool_statement.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_statement.cr#L1"},{"filename":"src/db/pool_unprepared_statement.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_unprepared_statement.cr#L1"},{"filename":"src/db/query_methods.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L1"},{"filename":"src/db/result_set.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L1"},{"filename":"src/db/serializable.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/serializable.cr#L1"},{"filename":"src/db/session_methods.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L1"},{"filename":"src/db/statement.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L1"},{"filename":"src/db/string_key_cache.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/string_key_cache.cr#L1"},{"filename":"src/db/transaction.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L1"},{"filename":"src/db/version.cr","line_number":1,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/version.cr#L1"},{"filename":"src/spec.cr","line_number":9,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L9"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"constants":[{"id":"Log","name":"Log","value":"::Log.for(self)"},{"id":"TYPES","name":"TYPES","value":"[Nil, String, Bool, Int32, Int64, Float32, Float64, Time, Bytes]","doc":"Types supported to interface with database driver.\nThese can be used in any `ResultSet#read` or any `Database#query` related\nmethod to be used as query parameters","summary":"

Types supported to interface with database driver.

"},{"id":"VERSION","name":"VERSION","value":"\"0.13.0\""}],"doc":"The DB module is a unified interface for database access.\nIndividual database systems are supported by specific database driver shards.\n\nAvailable drivers include:\n* [crystal-lang/crystal-sqlite3](https://github.com/crystal-lang/crystal-sqlite3) for SQLite\n* [crystal-lang/crystal-mysql](https://github.com/crystal-lang/crystal-mysql) for MySQL and MariaDB\n* [will/crystal-pg](https://github.com/will/crystal-pg) for PostgreSQL\n* [kaukas/crystal-cassandra](https://github.com/kaukas/crystal-cassandra) for Cassandra\n\nFor basic instructions on implementing a new database driver, check `Driver` and the existing drivers.\n\nDB manages a connection pool. The connection pool can be configured by query parameters to the\nconnection `URI` as described in `Database`.\n\n### Usage\n\nAssuming `crystal-sqlite3` is included a SQLite3 database can be opened with `#open`.\n\n```\ndb = DB.open \"sqlite3:./path/to/db/file.db\"\ndb.close\n```\n\nIf a block is given to `#open` the database is closed automatically\n\n```\nDB.open \"sqlite3:./file.db\" do |db|\n # work with db\nend # db is closed\n```\n\nIn the code above `db` is a `Database`. Methods available for querying it are described in `QueryMethods`.\n\nThree kind of statements can be performed:\n1. `Database#exec` waits no response from the database.\n2. `Database#scalar` reads a single value of the response.\n3. `Database#query` returns a ResultSet that allows iteration over the rows in the response and column information.\n\nAll of the above methods allows parametrised query. Either positional or named arguments.\n\nCheck a full working version:\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```\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### Object mapping\n\nThe `DB::Serializable` module implements a declarative mapping from DB result\nsets to Crystal types.","summary":"

The DB module is a unified interface for database access.

","class_methods":[{"html_id":"connect(uri:URI|String)-class-method","name":"connect","doc":"Opens a connection using the specified *uri*.\nThe scheme of the *uri* determines the driver to use.\nReturned connection must be closed by `Connection#close`.\nIf a block is used the connection is yielded and closed automatically.","summary":"

Opens a connection using the specified uri.

","abstract":false,"args":[{"name":"uri","external_name":"uri","restriction":"URI | String"}],"args_string":"(uri : URI | String)","args_html":"(uri : URI | String)","location":{"filename":"src/db.cr","line_number":140,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L140"},"def":{"name":"connect","args":[{"name":"uri","external_name":"uri","restriction":"URI | String"}],"visibility":"Public","body":"build_connection(uri)"}},{"html_id":"connect(uri:URI|String,&)-class-method","name":"connect","doc":"Opens a connection using the specified *uri*.\nThe scheme of the *uri* determines the driver to use.\nReturned connection must be closed by `Connection#close`.\nIf a block is used the connection is yielded and closed automatically.","summary":"

Opens a connection using the specified uri.

","abstract":false,"args":[{"name":"uri","external_name":"uri","restriction":"URI | String"}],"args_string":"(uri : URI | String, &)","args_html":"(uri : URI | String, &)","location":{"filename":"src/db.cr","line_number":145,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L145"},"def":{"name":"connect","args":[{"name":"uri","external_name":"uri","restriction":"URI | String"}],"yields":1,"block_arity":1,"visibility":"Public","body":"cnn = build_connection(uri)\nbegin\n yield cnn\nensure\n cnn.close\nend\n"}},{"html_id":"open(uri:URI|String)-class-method","name":"open","doc":"Creates a `Database` pool and opens initial connection(s) as specified in the connection *uri*.\nUse `DB#connect` to open a single connection.\n\nThe scheme of the *uri* determines the driver to use.\nConnection parameters such as hostname, user, database name, etc. are specified according\nto each database driver's specific format.\n\nThe returned database must be closed by `Database#close`.","summary":"

Creates a Database pool and opens initial connection(s) as specified in the connection uri.

","abstract":false,"args":[{"name":"uri","external_name":"uri","restriction":"URI | String"}],"args_string":"(uri : URI | String)","args_html":"(uri : URI | String)","location":{"filename":"src/db.cr","line_number":122,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L122"},"def":{"name":"open","args":[{"name":"uri","external_name":"uri","restriction":"URI | String"}],"visibility":"Public","body":"build_database(uri)"}},{"html_id":"open(uri:URI|String,&)-class-method","name":"open","doc":"Same as `#open` but the database is yielded and closed automatically at the end of the block.","summary":"

Same as #open but the database is yielded and closed automatically at the end of the block.

","abstract":false,"args":[{"name":"uri","external_name":"uri","restriction":"URI | String"}],"args_string":"(uri : URI | String, &)","args_html":"(uri : URI | String, &)","location":{"filename":"src/db.cr","line_number":127,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L127"},"def":{"name":"open","args":[{"name":"uri","external_name":"uri","restriction":"URI | String"}],"yields":1,"block_arity":1,"visibility":"Public","body":"db = build_database(uri)\nbegin\n yield db\nensure\n db.close\nend\n"}},{"html_id":"register_driver(driver_name,driver_class:Driver.class)-class-method","name":"register_driver","doc":"Registers a driver class for a given *driver_name*.\nShould be called by drivers implementors only.","summary":"

Registers a driver class for a given driver_name.

","abstract":false,"args":[{"name":"driver_name","external_name":"driver_name","restriction":""},{"name":"driver_class","external_name":"driver_class","restriction":"Driver.class"}],"args_string":"(driver_name, driver_class : Driver.class)","args_html":"(driver_name, driver_class : Driver.class)","location":{"filename":"src/db.cr","line_number":106,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L106"},"def":{"name":"register_driver","args":[{"name":"driver_name","external_name":"driver_name","restriction":""},{"name":"driver_class","external_name":"driver_class","restriction":"Driver.class"}],"visibility":"Public","body":"drivers[driver_name] = driver_class"}}],"macros":[{"html_id":"mapping(properties,strict=true)-macro","name":"mapping","doc":"The `DB.mapping` macro defines how an object is built from a `ResultSet`.\n\nIt takes hash literal as argument, in which attributes and types are defined.\nOnce defined, `ResultSet#read(t)` populates properties of the class from the\n`ResultSet`.\n\n```\nrequire \"db\"\n\nclass Employee\n DB.mapping({\n title: String,\n name: String,\n })\nend\n\nemployees = Employee.from_rs(db.query(\"SELECT title, name FROM employees\"))\nemployees[0].title # => \"Manager\"\nemployees[0].name # => \"John\"\n```\n\nAttributes not mapped with `DB.mapping` are not defined as properties.\nAlso, missing attributes raise a `DB::MappingException`.\n\nYou can also define attributes for each property.\n\n```\nclass Employee\n DB.mapping({\n title: String,\n name: {\n type: String,\n nilable: true,\n key: \"firstname\",\n },\n })\nend\n```\n\nAvailable attributes:\n\n* *type* (required) defines its type. In the example above, *title: String* is a shortcut to *title: {type: String}*.\n* *nilable* defines if a property can be a `Nil`.\n* **default**: value to use if the property is missing in the result set, or if it's `null` and `nilable` was not set to `true`. If the default value creates a new instance of an object (for example `[1, 2, 3]` or `SomeObject.new`), a different instance will be used each time a row is parsed.\n* *key* defines which column to read from a `ResultSet`. It defaults to the name of the property.\n* *converter* takes an alternate type for parsing. It requires a `#from_rs` method in that class, and returns an instance of the given type.\n\nThe mapping also automatically defines Crystal properties (getters and setters) for each\nof the keys. It doesn't define a constructor accepting those arguments, but you can provide\nan overload.\n\nThe macro basically defines a constructor accepting a `ResultSet` that reads from\nit and initializes this type's instance variables.\n\nThis macro also declares instance variables of the types given in the mapping.","summary":"

The DB.mapping macro defines how an object is built from a ResultSet.

\n

DEPRECATED Use DB::Serializable instead

","abstract":false,"args":[{"name":"properties","external_name":"properties","restriction":""},{"name":"strict","default_value":"true","external_name":"strict","restriction":""}],"args_string":"(properties, strict = true)","args_html":"(properties, strict = true)","location":{"filename":"src/db/mapping.cr","line_number":62,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/mapping.cr#L62"},"def":{"name":"mapping","args":[{"name":"properties","external_name":"properties","restriction":""},{"name":"strict","default_value":"true","external_name":"strict","restriction":""}],"visibility":"Public","body":" include ::DB::Mappable\n\n \n{% for key, value in properties %}\n {% unless value.is_a?(HashLiteral) || value.is_a?(NamedTupleLiteral)\n properties[key] = {type: value}\nend %}\n {% end %}\n\n\n \n{% for key, value in properties %}\n {% if value[:type].is_a?(Generic) && (value[:type].type_vars.map(&.resolve).includes?(Nil))\n value[:nilable] = true\nend %}\n\n {% if (value[:type].is_a?(Call) && (value[:type].name == \"|\")) && ((value[:type].receiver.resolve == Nil) || value[:type].args.map(&.resolve).any?(&.==(Nil))) %}\n {% value[:nilable] = true %}\n {% end %}\n {% end %}\n\n\n \n{% for key, value in properties %}\n @{{ key.id }} : {{ value[:type] }} {{ (value[:nilable] ? \"?\" : \"\").id }}\n\n def {{ key.id }}=(_{{ key.id }} : {{ value[:type] }} {{ (value[:nilable] ? \"?\" : \"\").id }})\n @{{ key.id }} = _{{ key.id }}\n end\n\n def {{ key.id }}\n @{{ key.id }}\n end\n {% end %}\n\n\n def self.from_rs(\n%rs\n : ::DB::ResultSet)\n \n%objs\n = Array(self).new\n \n%rs\n.each do\n \n%objs\n << self.new(\n%rs\n)\n \nend\n \n%objs\n\n \nensure\n \n%rs\n.close\n \nend\n\n def initialize(\n%rs\n : ::DB::ResultSet)\n \n{% for key, value in properties %}\n %var{key.id} = nil\n %found{key.id} = false\n {% end %}\n\n\n \n%rs\n.each_column do |col_name|\n case col_name\n \n{% for key, value in properties %}\n when {{ value[:key] || key.id.stringify }}\n %found{key.id} = true\n %var{key.id} =\n {% if value[:converter] %}\n {{ value[:converter] }}.from_rs(%rs)\n {% else %}{% if value[:nilable] || (value[:default] != nil) %}\n %rs.read(::Union({{ value[:type] }} | Nil))\n {% else %}\n %rs.read({{ value[:type] }})\n {% end %}{% end %}\n {% end %}\n\n \nelse\n \n{% if strict %}\n raise ::DB::MappingException.new(\"unknown result set attribute: #{col_name}\", self.class.to_s)\n {% else %}\n %rs.read\n {% end %}\n\n \nend\n \nend\n\n \n{% for key, value in properties %}\n {% if value[:nilable] || (value[:default] != nil) %}{% else %}\n if %var{key.id}.is_a?(Nil) && !%found{key.id}\n raise ::DB::MappingException.new(\"missing result set attribute: {{ (value[:key] || key).id }}\", self.class.to_s)\n end\n {% end %}\n {% end %}\n\n\n \n{% for key, value in properties %}\n {% if value[:nilable] %}\n {% if value[:default] != nil %}\n @{{ key.id }} = %found{key.id} ? %var{key.id} : {{ value[:default] }}\n {% else %}\n @{{ key.id }} = %var{key.id}\n {% end %}\n {% else %}{% if value[:default] != nil %}\n @{{ key.id }} = %var{key.id}.is_a?(Nil) ? {{ value[:default] }} : %var{key.id}\n {% else %}\n @{{ key.id }} = %var{key.id}.as({{ value[:type] }})\n {% end %}{% end %}\n {% end %}\n\n \nend\n \n"}},{"html_id":"mapping(**properties)-macro","name":"mapping","summary":"

DEPRECATED Use DB::Serializable instead

","abstract":false,"location":{"filename":"src/db/mapping.cr","line_number":154,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/mapping.cr#L154"},"def":{"name":"mapping","double_splat":{"name":"properties","external_name":"properties","restriction":""},"visibility":"Public","body":" ::DB.mapping(\n{{ properties }}\n)\n \n"}}],"types":[{"html_id":"db/DB/Any","path":"DB/Any.html","kind":"alias","full_name":"DB::Any","name":"Any","abstract":false,"locations":[{"filename":"src/db.cr","line_number":91,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L91"}],"repository_name":"db","program":false,"enum":false,"alias":true,"aliased":"(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | Nil)","aliased_html":"Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | Nil","const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"}},{"html_id":"db/DB/BeginTransaction","path":"DB/BeginTransaction.html","kind":"module","full_name":"DB::BeginTransaction","name":"BeginTransaction","abstract":false,"locations":[{"filename":"src/db/begin_transaction.cr","line_number":2,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/begin_transaction.cr#L2"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"including_types":[{"html_id":"db/DB/Connection","kind":"class","full_name":"DB::Connection","name":"Connection"},{"html_id":"db/DB/Transaction","kind":"class","full_name":"DB::Transaction","name":"Transaction"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"instance_methods":[{"html_id":"begin_transaction:Transaction-instance-method","name":"begin_transaction","doc":"Creates a transaction from the current context.\nIf is expected that either `Transaction#commit` or `Transaction#rollback`\nare called explicitly to release the context.","summary":"

Creates a transaction from the current context.

","abstract":true,"location":{"filename":"src/db/begin_transaction.cr","line_number":6,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/begin_transaction.cr#L6"},"def":{"name":"begin_transaction","return_type":"Transaction","visibility":"Public","body":""}},{"html_id":"transaction(&:Transaction->T):T|NilforallT-instance-method","name":"transaction","doc":"yields a transaction from the current context.\nQuery the database through `Transaction#connection` object.\nIf an exception is thrown within the block a rollback is performed.\nThe exception thrown is bubbled unless it is a `DB::Rollback`.\nFrom the yielded object `Transaction#commit` or `Transaction#rollback`\ncan be called explicitly.\nReturns the value of the block.","summary":"

yields a transaction from the current context.

","abstract":false,"location":{"filename":"src/db/begin_transaction.cr","line_number":15,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/begin_transaction.cr#L15"},"def":{"name":"transaction","yields":1,"block_arity":1,"block_arg":{"name":"","external_name":"","restriction":"(Transaction -> T)"},"return_type":"T | ::Nil","visibility":"Public","body":"rollback = false\ntx = begin_transaction.as(Transaction)\nbegin\n res = yield tx\nrescue DB::Rollback\n rollback = true\n res\nrescue e\n rollback = true\n raise(e)\nensure\n if tx.closed?\n else\n if rollback\n tx.rollback\n else\n tx.commit\n end\n end\nend\n"}}]},{"html_id":"db/DB/ColumnTypeMismatchError","path":"DB/ColumnTypeMismatchError.html","kind":"class","full_name":"DB::ColumnTypeMismatchError","name":"ColumnTypeMismatchError","abstract":false,"superclass":{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":66,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L66"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Raised when the type returned for the column value\ndoes not match the type expected.","summary":"

Raised when the type returned for the column value does not match the type expected.

","constructors":[{"html_id":"new(*,context:String,column_index:Int32,column_name:String,column_type:String,expected_type:String)-class-method","name":"new","abstract":false,"args":[{"name":"","external_name":"","restriction":""},{"name":"context","external_name":"context","restriction":"String"},{"name":"column_index","external_name":"column_index","restriction":"Int32"},{"name":"column_name","external_name":"column_name","restriction":"String"},{"name":"column_type","external_name":"column_type","restriction":"String"},{"name":"expected_type","external_name":"expected_type","restriction":"String"}],"args_string":"(*, context : String, column_index : Int32, column_name : String, column_type : String, expected_type : String)","args_html":"(*, context : String, column_index : Int32, column_name : String, column_type : String, expected_type : String)","location":{"filename":"src/db/error.cr","line_number":72,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L72"},"def":{"name":"new","args":[{"name":"","external_name":"","restriction":""},{"name":"context","external_name":"context","restriction":"String"},{"name":"column_index","external_name":"column_index","restriction":"Int32"},{"name":"column_name","external_name":"column_name","restriction":"String"},{"name":"column_type","external_name":"column_type","restriction":"String"},{"name":"expected_type","external_name":"expected_type","restriction":"String"}],"splat_index":0,"visibility":"Public","body":"_ = allocate\n_.initialize(context: context, column_index: column_index, column_name: column_name, column_type: column_type, expected_type: expected_type)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"column_index:Int32-instance-method","name":"column_index","abstract":false,"location":{"filename":"src/db/error.cr","line_number":67,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L67"},"def":{"name":"column_index","return_type":"Int32","visibility":"Public","body":"@column_index"}},{"html_id":"column_name:String-instance-method","name":"column_name","abstract":false,"location":{"filename":"src/db/error.cr","line_number":68,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L68"},"def":{"name":"column_name","return_type":"String","visibility":"Public","body":"@column_name"}},{"html_id":"column_type:String-instance-method","name":"column_type","abstract":false,"location":{"filename":"src/db/error.cr","line_number":69,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L69"},"def":{"name":"column_type","return_type":"String","visibility":"Public","body":"@column_type"}},{"html_id":"expected_type:String-instance-method","name":"expected_type","abstract":false,"location":{"filename":"src/db/error.cr","line_number":70,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L70"},"def":{"name":"expected_type","return_type":"String","visibility":"Public","body":"@expected_type"}}]},{"html_id":"db/DB/Connection","path":"DB/Connection.html","kind":"class","full_name":"DB::Connection","name":"Connection","abstract":true,"superclass":{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"db/DB/BeginTransaction","kind":"module","full_name":"DB::BeginTransaction","name":"BeginTransaction"},{"html_id":"db/DB/SessionMethods","kind":"module","full_name":"DB::SessionMethods","name":"SessionMethods"},{"html_id":"db/DB/QueryMethods","kind":"module","full_name":"DB::QueryMethods","name":"QueryMethods"},{"html_id":"db/DB/Disposable","kind":"module","full_name":"DB::Disposable","name":"Disposable"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/connection.cr","line_number":21,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L21"},{"filename":"src/db/error.cr","line_number":2,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L2"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/DB/BeginTransaction","kind":"module","full_name":"DB::BeginTransaction","name":"BeginTransaction"},{"html_id":"db/DB/Disposable","kind":"module","full_name":"DB::Disposable","name":"Disposable"},{"html_id":"db/DB/SessionMethods","kind":"module","full_name":"DB::SessionMethods","name":"SessionMethods"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Database driver implementors must subclass `Connection`.\n\nRepresents one active connection to a database.\n\nUsers should never instantiate a `Connection` manually. Use `DB#open` or `Database#connection`.\n\nRefer to `QueryMethods` for documentation about querying the database through this connection.\n\n### Note to implementors\n\nThe connection must be initialized in `#initialize` and closed in `#do_close`.\n\nOverride `#build_prepared_statement` method in order to return a prepared `Statement` to allow querying.\nOverride `#build_unprepared_statement` method in order to return a unprepared `Statement` to allow querying.\nSee also `Statement` to define how the statements are executed.\n\nIf at any give moment the connection is lost a DB::ConnectionLost should be raised. This will\nallow the connection pool to try to reconnect or use another connection if available.\n","summary":"

Database driver implementors must subclass Connection.

","constructors":[{"html_id":"new(options:Options)-class-method","name":"new","abstract":false,"args":[{"name":"options","external_name":"options","restriction":"Options"}],"args_string":"(options : Options)","args_html":"(options : Options)","location":{"filename":"src/db/connection.cr","line_number":46,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L46"},"def":{"name":"new","args":[{"name":"options","external_name":"options","restriction":"Options"}],"visibility":"Public","body":"_ = allocate\n_.initialize(options)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"begin_transaction:Transaction-instance-method","name":"begin_transaction","doc":"Creates a transaction from the current context.\nIf is expected that either `Transaction#commit` or `Transaction#rollback`\nare called explicitly to release the context.","summary":"

Creates a transaction from the current context.

","abstract":false,"location":{"filename":"src/db/connection.cr","line_number":72,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L72"},"def":{"name":"begin_transaction","return_type":"Transaction","visibility":"Public","body":"if @transaction\n raise(DB::Error.new(\"There is an existing transaction in this connection\"))\nend\n@transaction = true\ncreate_transaction\n"}},{"html_id":"prepared_statements?:Bool-instance-method","name":"prepared_statements?","doc":"Returns whether by default the statements should\nbe prepared or not.","summary":"

Returns whether by default the statements should be prepared or not.

","abstract":false,"location":{"filename":"src/db/connection.cr","line_number":49,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L49"},"def":{"name":"prepared_statements?","return_type":"Bool","visibility":"Public","body":"@options.prepared_statements"}},{"html_id":"prepared_statements_cache?:Bool-instance-method","name":"prepared_statements_cache?","abstract":false,"location":{"filename":"src/db/connection.cr","line_number":53,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L53"},"def":{"name":"prepared_statements_cache?","return_type":"Bool","visibility":"Public","body":"@options.prepared_statements_cache"}},{"html_id":"release-instance-method","name":"release","doc":"return this connection to the pool\nmanaged by the database. Should be used\nonly if the connection was obtained by `Database#checkout`.","summary":"

return this connection to the pool managed by the database.

","abstract":false,"location":{"filename":"src/db/connection.cr","line_number":100,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L100"},"def":{"name":"release","visibility":"Public","body":"context.release(self)"}}],"types":[{"html_id":"db/DB/Connection/Options","path":"DB/Connection/Options.html","kind":"struct","full_name":"DB::Connection::Options","name":"Options","abstract":false,"superclass":{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/connection.cr","line_number":26,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L26"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB/Connection","kind":"class","full_name":"DB::Connection","name":"Connection"},"class_methods":[{"html_id":"from_http_params(params:HTTP::Params,default=Options.new)-class-method","name":"from_http_params","abstract":false,"args":[{"name":"params","external_name":"params","restriction":"HTTP::Params"},{"name":"default","default_value":"Options.new","external_name":"default","restriction":""}],"args_string":"(params : HTTP::Params, default = Options.new)","args_html":"(params : HTTP::Params, default = Options.new)","location":{"filename":"src/db/connection.cr","line_number":31,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L31"},"def":{"name":"from_http_params","args":[{"name":"params","external_name":"params","restriction":"HTTP::Params"},{"name":"default","default_value":"Options.new","external_name":"default","restriction":""}],"visibility":"Public","body":"Options.new(prepared_statements: DB.fetch_bool(params, \"prepared_statements\", default.prepared_statements), prepared_statements_cache: DB.fetch_bool(params, \"prepared_statements_cache\", default.prepared_statements))"}}],"constructors":[{"html_id":"new(prepared_statements:Bool=true,prepared_statements_cache:Bool=true)-class-method","name":"new","abstract":false,"args":[{"name":"prepared_statements","default_value":"true","external_name":"prepared_statements","restriction":"Bool"},{"name":"prepared_statements_cache","default_value":"true","external_name":"prepared_statements_cache","restriction":"Bool"}],"args_string":"(prepared_statements : Bool = true, prepared_statements_cache : Bool = true)","args_html":"(prepared_statements : Bool = true, prepared_statements_cache : Bool = true)","location":{"filename":"src/db/connection.cr","line_number":26,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L26"},"def":{"name":"new","args":[{"name":"prepared_statements","default_value":"true","external_name":"prepared_statements","restriction":"Bool"},{"name":"prepared_statements_cache","default_value":"true","external_name":"prepared_statements_cache","restriction":"Bool"}],"visibility":"Public","body":"_ = allocate\n_.initialize(prepared_statements, prepared_statements_cache)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"clone-instance-method","name":"clone","abstract":false,"location":{"filename":"src/db/connection.cr","line_number":26,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L26"},"def":{"name":"clone","visibility":"Public","body":"self.class.new(@prepared_statements.clone, @prepared_statements_cache.clone)"}},{"html_id":"copy_with(prepared_statements_prepared_statements=@prepared_statements,prepared_statements_cache_prepared_statements_cache=@prepared_statements_cache)-instance-method","name":"copy_with","abstract":false,"args":[{"name":"_prepared_statements","default_value":"@prepared_statements","external_name":"prepared_statements","restriction":""},{"name":"_prepared_statements_cache","default_value":"@prepared_statements_cache","external_name":"prepared_statements_cache","restriction":""}],"args_string":"(prepared_statements _prepared_statements = @prepared_statements, prepared_statements_cache _prepared_statements_cache = @prepared_statements_cache)","args_html":"(prepared_statements _prepared_statements = @prepared_statements, prepared_statements_cache _prepared_statements_cache = @prepared_statements_cache)","location":{"filename":"src/db/connection.cr","line_number":26,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection.cr#L26"},"def":{"name":"copy_with","args":[{"name":"_prepared_statements","default_value":"@prepared_statements","external_name":"prepared_statements","restriction":""},{"name":"_prepared_statements_cache","default_value":"@prepared_statements_cache","external_name":"prepared_statements_cache","restriction":""}],"visibility":"Public","body":"self.class.new(_prepared_statements, _prepared_statements_cache)"}},{"html_id":"prepared_statements:Bool-instance-method","name":"prepared_statements","abstract":false,"def":{"name":"prepared_statements","return_type":"Bool","visibility":"Public","body":"@prepared_statements"}},{"html_id":"prepared_statements_cache:Bool-instance-method","name":"prepared_statements_cache","abstract":false,"def":{"name":"prepared_statements_cache","return_type":"Bool","visibility":"Public","body":"@prepared_statements_cache"}}]}]},{"html_id":"db/DB/ConnectionBuilder","path":"DB/ConnectionBuilder.html","kind":"class","full_name":"DB::ConnectionBuilder","name":"ConnectionBuilder","abstract":true,"superclass":{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/connection_builder.cr","line_number":5,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection_builder.cr#L5"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"A connection factory with a specific configuration.\n\nSee `Driver#connection_builder`.","summary":"

A connection factory with a specific configuration.

","instance_methods":[{"html_id":"build:Connection-instance-method","name":"build","abstract":true,"location":{"filename":"src/db/connection_builder.cr","line_number":6,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection_builder.cr#L6"},"def":{"name":"build","return_type":"Connection","visibility":"Public","body":""}}]},{"html_id":"db/DB/ConnectionContext","path":"DB/ConnectionContext.html","kind":"module","full_name":"DB::ConnectionContext","name":"ConnectionContext","abstract":false,"locations":[{"filename":"src/db/connection_context.cr","line_number":2,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection_context.cr#L2"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"including_types":[{"html_id":"db/DB/Database","kind":"class","full_name":"DB::Database","name":"Database"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"instance_methods":[{"html_id":"discard(connection:Connection)-instance-method","name":"discard","doc":"Indicates that the *connection* was permanently closed\nand should not be used in the future.","summary":"

Indicates that the connection was permanently closed and should not be used in the future.

","abstract":true,"args":[{"name":"connection","external_name":"connection","restriction":"Connection"}],"args_string":"(connection : Connection)","args_html":"(connection : Connection)","location":{"filename":"src/db/connection_context.cr","line_number":5,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection_context.cr#L5"},"def":{"name":"discard","args":[{"name":"connection","external_name":"connection","restriction":"Connection"}],"visibility":"Public","body":""}},{"html_id":"release(connection:Connection)-instance-method","name":"release","doc":"Indicates that the *connection* is no longer needed\nand can be reused in the future.","summary":"

Indicates that the connection is no longer needed and can be reused in the future.

","abstract":true,"args":[{"name":"connection","external_name":"connection","restriction":"Connection"}],"args_string":"(connection : Connection)","args_html":"(connection : Connection)","location":{"filename":"src/db/connection_context.cr","line_number":9,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/connection_context.cr#L9"},"def":{"name":"release","args":[{"name":"connection","external_name":"connection","restriction":"Connection"}],"visibility":"Public","body":""}}]},{"html_id":"db/DB/ConnectionLost","path":"DB/ConnectionLost.html","kind":"class","full_name":"DB::ConnectionLost","name":"ConnectionLost","abstract":false,"superclass":{"html_id":"db/DB/PoolResourceLost","kind":"class","full_name":"DB::PoolResourceLost","name":"PoolResourceLost"},"ancestors":[{"html_id":"db/DB/PoolResourceLost","kind":"class","full_name":"DB::PoolResourceLost","name":"PoolResourceLost"},{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":45,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L45"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Raised when an established connection is lost\nprobably due to socket/network issues.\nIt is used by the connection pool retry logic.","summary":"

Raised when an established connection is lost probably due to socket/network issues.

","constructors":[{"html_id":"new(resource:T,cause:Exception|Nil=nil)-class-method","name":"new","abstract":false,"args":[{"name":"resource","external_name":"resource","restriction":"T"},{"name":"cause","default_value":"nil","external_name":"cause","restriction":"Exception | ::Nil"}],"args_string":"(resource : T, cause : Exception | Nil = nil)","args_html":"(resource : T, cause : Exception | Nil = nil)","location":{"filename":"src/db/error.cr","line_number":33,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L33"},"def":{"name":"new","args":[{"name":"resource","external_name":"resource","restriction":"T"},{"name":"cause","default_value":"nil","external_name":"cause","restriction":"Exception | ::Nil"}],"visibility":"Public","body":"_ = allocate\n_.initialize(resource, cause)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"connection-instance-method","name":"connection","abstract":false,"location":{"filename":"src/db/error.cr","line_number":46,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L46"},"def":{"name":"connection","visibility":"Public","body":"resource"}}]},{"html_id":"db/DB/ConnectionRefused","path":"DB/ConnectionRefused.html","kind":"class","full_name":"DB::ConnectionRefused","name":"ConnectionRefused","abstract":false,"superclass":{"html_id":"db/DB/PoolResourceRefused","kind":"class","full_name":"DB::PoolResourceRefused","name":"PoolResourceRefused"},"ancestors":[{"html_id":"db/DB/PoolResourceRefused","kind":"class","full_name":"DB::PoolResourceRefused","name":"PoolResourceRefused"},{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":54,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L54"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Raised when a connection is unable to be established\nprobably due to socket/network or configuration issues.\nIt is used by the connection pool retry logic.","summary":"

Raised when a connection is unable to be established probably due to socket/network or configuration issues.

"},{"html_id":"db/DB/Database","path":"DB/Database.html","kind":"class","full_name":"DB::Database","name":"Database","abstract":false,"superclass":{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"db/DB/ConnectionContext","kind":"module","full_name":"DB::ConnectionContext","name":"ConnectionContext"},{"html_id":"db/DB/SessionMethods","kind":"module","full_name":"DB::SessionMethods","name":"SessionMethods"},{"html_id":"db/DB/QueryMethods","kind":"module","full_name":"DB::QueryMethods","name":"QueryMethods"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/database.cr","line_number":31,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/database.cr#L31"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/DB/ConnectionContext","kind":"module","full_name":"DB::ConnectionContext","name":"ConnectionContext"},{"html_id":"db/DB/SessionMethods","kind":"module","full_name":"DB::SessionMethods","name":"SessionMethods"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Acts as an entry point for database access.\nConnections are managed by a pool.\nUse `DB#open` to create a `Database` instance.\n\nRefer to `QueryMethods` and `SessionMethods` for documentation about querying the database.\n\n## Database URI\n\nConnection parameters are usually in a URI. The format is specified by the individual\ndatabase drivers, yet there are some common properties names usually shared.\nSee the [reference book](https://crystal-lang.org/reference/database/) for examples.\n\nThe connection pool can be configured from URI parameters:\n\n - `initial_pool_size` (default 1)\n - `max_pool_size` (default 0 = unlimited)\n - `max_idle_pool_size` (default 1)\n - `checkout_timeout` (default 5.0)\n - `retry_attempts` (default 1)\n - `retry_delay` (in seconds, default 1.0)\n\nWhen querying a database, prepared statements are used by default.\nThis can be changed from the `prepared_statements` URI parameter:\n\n - `prepared_statements` (true, or false, default true)\n","summary":"

Acts as an entry point for database access.

","constructors":[{"html_id":"new(connection_options:Connection::Options,pool_options:Pool::Options,&factory:->Connection)-class-method","name":"new","doc":"Initialize a database with the specified options and connection factory.\nThis covers more advanced use cases that might not be supported by an URI connection string such as tunneling connection.","summary":"

Initialize a database with the specified options and connection factory.

","abstract":false,"args":[{"name":"connection_options","external_name":"connection_options","restriction":"Connection::Options"},{"name":"pool_options","external_name":"pool_options","restriction":"Pool::Options"}],"args_string":"(connection_options : Connection::Options, pool_options : Pool::Options, &factory : -> Connection)","args_html":"(connection_options : Connection::Options, pool_options : Pool::Options, &factory : -> Connection)","location":{"filename":"src/db/database.cr","line_number":44,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/database.cr#L44"},"def":{"name":"new","args":[{"name":"connection_options","external_name":"connection_options","restriction":"Connection::Options"},{"name":"pool_options","external_name":"pool_options","restriction":"Pool::Options"}],"yields":0,"block_arity":0,"block_arg":{"name":"factory","external_name":"factory","restriction":"(-> Connection)"},"visibility":"Public","body":"_ = allocate\n_.initialize(connection_options, pool_options, &factory) do\n yield\nend\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"checkout-instance-method","name":"checkout","doc":"returns a connection from the pool\nthe returned connection must be returned\nto the pool by explictly calling `Connection#release`","summary":"

returns a connection from the pool the returned connection must be returned to the pool by explictly calling Connection#release

","abstract":false,"location":{"filename":"src/db/database.cr","line_number":126,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/database.cr#L126"},"def":{"name":"checkout","visibility":"Public","body":"connection = @pool.checkout\nconnection.auto_release = false\nconnection\n"}},{"html_id":"close-instance-method","name":"close","doc":"Closes all connection to the database.","summary":"

Closes all connection to the database.

","abstract":false,"location":{"filename":"src/db/database.cr","line_number":82,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/database.cr#L82"},"def":{"name":"close","visibility":"Public","body":"@pool.close"}},{"html_id":"prepared_statements?:Bool-instance-method","name":"prepared_statements?","doc":"Returns whether by default the statements should\nbe prepared or not.","summary":"

Returns whether by default the statements should be prepared or not.

","abstract":false,"location":{"filename":"src/db/database.cr","line_number":57,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/database.cr#L57"},"def":{"name":"prepared_statements?","return_type":"Bool","visibility":"Public","body":"@connection_options.prepared_statements"}},{"html_id":"prepared_statements_cache?:Bool-instance-method","name":"prepared_statements_cache?","abstract":false,"location":{"filename":"src/db/database.cr","line_number":61,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/database.cr#L61"},"def":{"name":"prepared_statements_cache?","return_type":"Bool","visibility":"Public","body":"@connection_options.prepared_statements_cache"}},{"html_id":"setup_connection(&proc:Connection->Nil)-instance-method","name":"setup_connection","doc":"Run the specified block every time a new connection is established, yielding the new connection\nto the block.\n\n```\ndb = DB.open(DB_URL)\ndb.setup_connection do |connection|\n connection.exec \"SET TIME ZONE 'America/New_York'\"\nend\n```","summary":"

Run the specified block every time a new connection is established, yielding the new connection to the block.

","abstract":false,"location":{"filename":"src/db/database.cr","line_number":74,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/database.cr#L74"},"def":{"name":"setup_connection","yields":1,"block_arity":1,"block_arg":{"name":"proc","external_name":"proc","restriction":"(Connection -> Nil)"},"visibility":"Public","body":"@setup_connection = proc\n@pool.each_resource do |conn|\n @setup_connection.call(conn)\nend\n"}},{"html_id":"transaction(&)-instance-method","name":"transaction","doc":"yields a `Transaction` from a connection of the pool\nRefer to `BeginTransaction#transaction` for documentation.","summary":"

yields a Transaction from a connection of the pool Refer to BeginTransaction#transaction for documentation.

","abstract":false,"location":{"filename":"src/db/database.cr","line_number":134,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/database.cr#L134"},"def":{"name":"transaction","yields":1,"block_arity":1,"visibility":"Public","body":"using_connection do |cnn|\n cnn.transaction do |tx|\n yield tx\n end\nend"}},{"html_id":"using_connection(&)-instance-method","name":"using_connection","doc":"yields a connection from the pool\nthe connection is returned to the pool\nwhen the block ends","summary":"

yields a connection from the pool the connection is returned to the pool when the block ends

","abstract":false,"location":{"filename":"src/db/database.cr","line_number":114,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/database.cr#L114"},"def":{"name":"using_connection","yields":1,"block_arity":1,"visibility":"Public","body":"connection = self.checkout\nbegin\n yield connection\nensure\n connection.release\nend\n"}}]},{"html_id":"db/DB/Disposable","path":"DB/Disposable.html","kind":"module","full_name":"DB::Disposable","name":"Disposable","abstract":false,"locations":[{"filename":"src/db/disposable.cr","line_number":3,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/disposable.cr#L3"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"including_types":[{"html_id":"db/DB/Connection","kind":"class","full_name":"DB::Connection","name":"Connection"},{"html_id":"db/DB/ResultSet","kind":"class","full_name":"DB::ResultSet","name":"ResultSet"},{"html_id":"db/DB/Statement","kind":"class","full_name":"DB::Statement","name":"Statement"},{"html_id":"db/DB/Transaction","kind":"class","full_name":"DB::Transaction","name":"Transaction"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Generic module to encapsulate disposable db resources.","summary":"

Generic module to encapsulate disposable db resources.

","instance_methods":[{"html_id":"close-instance-method","name":"close","doc":"Closes this object.","summary":"

Closes this object.

","abstract":false,"location":{"filename":"src/db/disposable.cr","line_number":9,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/disposable.cr#L9"},"def":{"name":"close","visibility":"Public","body":"if @closed\n return\nend\ndo_close\n@closed = true\n"}},{"html_id":"closed?-instance-method","name":"closed?","doc":"Returns `true` if this object is closed. See `#close`.","summary":"

Returns true if this object is closed.

","abstract":false,"location":{"filename":"src/db/disposable.cr","line_number":16,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/disposable.cr#L16"},"def":{"name":"closed?","visibility":"Public","body":"@closed"}}]},{"html_id":"db/DB/Driver","path":"DB/Driver.html","kind":"class","full_name":"DB::Driver","name":"Driver","abstract":true,"superclass":{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/driver.cr","line_number":44,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/driver.cr#L44"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Database driver implementors must subclass `Driver`,\nregister with a driver_name using `DB#register_driver` and\noverride the factory method `#connection_builder`.\n\n```\nrequire \"db\"\n\nclass FakeDriver < DB::Driver\n class FakeConnectionBuilder < DB::ConnectionBuilder\n def initialize(@options : DB::Connection::Options)\n end\n\n def build : DB::Connection\n FakeConnection.new(@options)\n end\n end\n\n def connection_builder(uri : URI) : ConnectionBuilder\n params = HTTP::Params.parse(uri.query || \"\")\n options = connection_options(params)\n # If needed, parse custom options from uri here\n # so they are parsed only once.\n FakeConnectionBuilder.new(options)\n end\nend\n\nDB.register_driver \"fake\", FakeDriver\n```\n\nAccess to this fake database will be available with\n\n```\nDB.open \"fake://...\" do |db|\n # ... use db ...\nend\n```\n\nRefer to `Connection`, `Statement` and `ResultSet` for further\ndriver implementation instructions.\n\nOverride `#connection_options` and `#pool_options` to provide custom\ndefaults or parsing of the connection string URI.","summary":"

Database driver implementors must subclass Driver, register with a driver_name using DB#register_driver and override the factory method #connection_builder.

","instance_methods":[{"html_id":"connection_builder(uri:URI):ConnectionBuilder-instance-method","name":"connection_builder","doc":"Returns a new connection factory.\n\nNOTE: For implementors *uri* should be parsed once. If all the options\nare sound a ConnectionBuilder is returned.","summary":"

Returns a new connection factory.

","abstract":true,"args":[{"name":"uri","external_name":"uri","restriction":"URI"}],"args_string":"(uri : URI) : ConnectionBuilder","args_html":"(uri : URI) : ConnectionBuilder","location":{"filename":"src/db/driver.cr","line_number":49,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/driver.cr#L49"},"def":{"name":"connection_builder","args":[{"name":"uri","external_name":"uri","restriction":"URI"}],"return_type":"ConnectionBuilder","visibility":"Public","body":""}},{"html_id":"connection_options(params:HTTP::Params):Connection::Options-instance-method","name":"connection_options","abstract":false,"args":[{"name":"params","external_name":"params","restriction":"HTTP::Params"}],"args_string":"(params : HTTP::Params) : Connection::Options","args_html":"(params : HTTP::Params) : Connection::Options","location":{"filename":"src/db/driver.cr","line_number":51,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/driver.cr#L51"},"def":{"name":"connection_options","args":[{"name":"params","external_name":"params","restriction":"HTTP::Params"}],"return_type":"Connection::Options","visibility":"Public","body":"Connection::Options.from_http_params(params)"}},{"html_id":"pool_options(params:HTTP::Params):Pool::Options-instance-method","name":"pool_options","abstract":false,"args":[{"name":"params","external_name":"params","restriction":"HTTP::Params"}],"args_string":"(params : HTTP::Params) : Pool::Options","args_html":"(params : HTTP::Params) : Pool::Options","location":{"filename":"src/db/driver.cr","line_number":55,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/driver.cr#L55"},"def":{"name":"pool_options","args":[{"name":"params","external_name":"params","restriction":"HTTP::Params"}],"return_type":"Pool::Options","visibility":"Public","body":"Pool::Options.from_http_params(params)"}}]},{"html_id":"db/DB/DriverSpecs","path":"DB/DriverSpecs.html","kind":"class","full_name":"DB::DriverSpecs(DBAnyType)","name":"DriverSpecs","abstract":false,"superclass":{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/spec.cr","line_number":51,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L51"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Helper class to ensure behaviour of custom drivers\n\n```\nrequire \"db/spec\"\n\nDB::DriverSpecs(DB::Any).run do\n # How to connect to database\n connection_string \"scheme://database_url\"\n\n # Clean up database if needed using before/after callbacks\n before do\n # ...\n end\n\n after do\n # ...\n end\n\n # Sample values that will be stored, retrieved across many specs\n sample_value \"hello\", \"varchar(25)\", \"'hello'\"\n\n it \"custom spec with a db initialized\" do |db|\n # assert something using *db*\n end\n\n # Configure the appropiate syntax for different commands needed to run the specs\n binding_syntax do |index|\n \"?\"\n end\n\n create_table_1column_syntax do |table_name, col1|\n \"create table #{table_name} (#{col1.name} #{col1.sql_type} #{col1.null ? \"NULL\" : \"NOT NULL\"})\"\n end\nend\n```\n\nThe following methods needs to be called to configure the appropiate syntax\nfor different commands and allow all the specs to run: `binding_syntax`, `create_table_1column_syntax`,\n`create_table_2columns_syntax`, `select_1column_syntax`, `select_2columns_syntax`, `select_count_syntax`,\n`select_scalar_syntax`, `insert_1column_syntax`, `insert_2columns_syntax`, `drop_table_if_exists_syntax`.\n","summary":"

Helper class to ensure behaviour of custom drivers

","class_methods":[{"html_id":"run(description=\"asadb\",&)-class-method","name":"run","abstract":false,"args":[{"name":"description","default_value":"\"as a db\"","external_name":"description","restriction":""}],"args_string":"(description = \"as a db\", &)","args_html":"(description = "as a db", &)","location":{"filename":"src/spec.cr","line_number":533,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L533"},"def":{"name":"run","args":[{"name":"description","default_value":"\"as a db\"","external_name":"description","restriction":""}],"yields":1,"block_arity":1,"visibility":"Public","body":"ctx = self.new\nwith ctx yield ctx\ndescribe(description) do\n ctx.include_shared_specs\n ctx.its.each do |db_it|\n case db_it.prepared\n when :default\n it(db_it.description, db_it.file, db_it.line, db_it.end_line) do\n ctx.with_db do |db|\n db_it.block.call(db)\n nil\n end\n end\n when :both\n values = [] of Bool\n if ctx.support_prepared\n values << true\n end\n if ctx.support_unprepared\n values << false\n end\n case values.size\n when 0\n raise(\"Neither prepared non unprepared statements allowed\")\n when 1\n it(db_it.description, db_it.file, db_it.line, db_it.end_line) do\n ctx.with_db do |db|\n db_it.block.call(db)\n nil\n end\n end\n else\n values.each do |prepared_statements|\n it(\"#{db_it.description} (prepared_statements=#{prepared_statements})\", db_it.file, db_it.line, db_it.end_line) do\n ctx.with_db(\"prepared_statements=#{prepared_statements}\") do |db|\n db_it.block.call(db)\n nil\n end\n end\n end\n end\n else\n raise(\"Invalid prepared value. Allowed values are :both and :default\")\n end\n end\nend\n"}}],"instance_methods":[{"html_id":"after(&after:->Nil)-instance-method","name":"after","abstract":false,"location":{"filename":"src/spec.cr","line_number":63,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L63"},"def":{"name":"after","yields":0,"block_arity":0,"block_arg":{"name":"after","external_name":"after","restriction":"(-> Nil)"},"visibility":"Public","body":"@after = after"}},{"html_id":"before(&before:->Nil)-instance-method","name":"before","abstract":false,"location":{"filename":"src/spec.cr","line_number":60,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L60"},"def":{"name":"before","yields":0,"block_arity":0,"block_arg":{"name":"before","external_name":"before","restriction":"(-> Nil)"},"visibility":"Public","body":"@before = before"}},{"html_id":"binding_syntax(&binding_syntax:Proc(Int32,String))-instance-method","name":"binding_syntax","abstract":false,"location":{"filename":"src/spec.cr","line_number":110,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L110"},"def":{"name":"binding_syntax","yields":0,"block_arity":0,"block_arg":{"name":"binding_syntax","external_name":"binding_syntax","restriction":"Proc(Int32, String)"},"visibility":"Public","body":"@binding_syntax = binding_syntax"}},{"html_id":"connection_string(connection_string:String)-instance-method","name":"connection_string","abstract":false,"args":[{"name":"connection_string","external_name":"connection_string","restriction":"String"}],"args_string":"(connection_string : String)","args_html":"(connection_string : String)","location":{"filename":"src/spec.cr","line_number":109,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L109"},"def":{"name":"connection_string","args":[{"name":"connection_string","external_name":"connection_string","restriction":"String"}],"visibility":"Public","body":"@connection_string = connection_string"}},{"html_id":"create_table_1column_syntax(&create_table_1column_syntax:Proc(String,ColumnDef,String))-instance-method","name":"create_table_1column_syntax","abstract":false,"location":{"filename":"src/spec.cr","line_number":112,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L112"},"def":{"name":"create_table_1column_syntax","yields":0,"block_arity":0,"block_arg":{"name":"create_table_1column_syntax","external_name":"create_table_1column_syntax","restriction":"Proc(String, ColumnDef, String)"},"visibility":"Public","body":"@create_table_1column_syntax = create_table_1column_syntax"}},{"html_id":"create_table_2columns_syntax(&create_table_2columns_syntax:Proc(String,ColumnDef,ColumnDef,String))-instance-method","name":"create_table_2columns_syntax","abstract":false,"location":{"filename":"src/spec.cr","line_number":113,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L113"},"def":{"name":"create_table_2columns_syntax","yields":0,"block_arity":0,"block_arg":{"name":"create_table_2columns_syntax","external_name":"create_table_2columns_syntax","restriction":"Proc(String, ColumnDef, ColumnDef, String)"},"visibility":"Public","body":"@create_table_2columns_syntax = create_table_2columns_syntax"}},{"html_id":"drop_table_if_exists_syntax(&drop_table_if_exists_syntax:Proc(String,String))-instance-method","name":"drop_table_if_exists_syntax","abstract":false,"location":{"filename":"src/spec.cr","line_number":119,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L119"},"def":{"name":"drop_table_if_exists_syntax","yields":0,"block_arity":0,"block_arg":{"name":"drop_table_if_exists_syntax","external_name":"drop_table_if_exists_syntax","restriction":"Proc(String, String)"},"visibility":"Public","body":"@drop_table_if_exists_syntax = drop_table_if_exists_syntax"}},{"html_id":"encode_null(encode_null:String)-instance-method","name":"encode_null","abstract":false,"args":[{"name":"encode_null","external_name":"encode_null","restriction":"String"}],"args_string":"(encode_null : String)","args_html":"(encode_null : String)","location":{"filename":"src/spec.cr","line_number":66,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L66"},"def":{"name":"encode_null","args":[{"name":"encode_null","external_name":"encode_null","restriction":"String"}],"visibility":"Public","body":"@encode_null = encode_null"}},{"html_id":"insert_1column_syntax(&insert_1column_syntax:Proc(String,ColumnDef,String,String))-instance-method","name":"insert_1column_syntax","abstract":false,"location":{"filename":"src/spec.cr","line_number":114,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L114"},"def":{"name":"insert_1column_syntax","yields":0,"block_arity":0,"block_arg":{"name":"insert_1column_syntax","external_name":"insert_1column_syntax","restriction":"Proc(String, ColumnDef, String, String)"},"visibility":"Public","body":"@insert_1column_syntax = insert_1column_syntax"}},{"html_id":"insert_2columns_syntax(&insert_2columns_syntax:Proc(String,ColumnDef,String,ColumnDef,String,String))-instance-method","name":"insert_2columns_syntax","abstract":false,"location":{"filename":"src/spec.cr","line_number":115,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L115"},"def":{"name":"insert_2columns_syntax","yields":0,"block_arity":0,"block_arg":{"name":"insert_2columns_syntax","external_name":"insert_2columns_syntax","restriction":"Proc(String, ColumnDef, String, ColumnDef, String, String)"},"visibility":"Public","body":"@insert_2columns_syntax = insert_2columns_syntax"}},{"html_id":"it(description=\"assert\",prepared=:default,file=__FILE__,line=__LINE__,end_line=__END_LINE__,&block:DB::Database->)-instance-method","name":"it","abstract":false,"args":[{"name":"description","default_value":"\"assert\"","external_name":"description","restriction":""},{"name":"prepared","default_value":":default","external_name":"prepared","restriction":""},{"name":"file","default_value":"__FILE__","external_name":"file","restriction":""},{"name":"line","default_value":"__LINE__","external_name":"line","restriction":""},{"name":"end_line","default_value":"__END_LINE__","external_name":"end_line","restriction":""}],"args_string":"(description = \"assert\", prepared = :default, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block : DB::Database -> )","args_html":"(description = "assert", prepared = :default, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block : DB::Database -> )","location":{"filename":"src/spec.cr","line_number":125,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L125"},"def":{"name":"it","args":[{"name":"description","default_value":"\"assert\"","external_name":"description","restriction":""},{"name":"prepared","default_value":":default","external_name":"prepared","restriction":""},{"name":"file","default_value":"__FILE__","external_name":"file","restriction":""},{"name":"line","default_value":"__LINE__","external_name":"line","restriction":""},{"name":"end_line","default_value":"__END_LINE__","external_name":"end_line","restriction":""}],"yields":1,"block_arity":1,"block_arg":{"name":"block","external_name":"block","restriction":"(DB::Database ->)"},"visibility":"Public","body":"@its << (SpecIt.new(description, prepared, file, line, end_line, block))"}},{"html_id":"its-instance-method","name":"its","abstract":false,"location":{"filename":"src/spec.cr","line_number":123,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L123"},"def":{"name":"its","visibility":"Public","body":"@its"}},{"html_id":"sample_value(value,sql_type,value_encoded,*,type_safe_value=true)-instance-method","name":"sample_value","doc":"Use *value* as sample value that should be stored in columns of type *sql_type*.\n*value_encoded* is driver specific expression that should generate that value in the database.\n*type_safe_value* indicates whether *value_encoded* is expected to generate the *value* even without\nbeen stored in a table (default `true`).","summary":"

Use value as sample value that should be stored in columns of type sql_type.

","abstract":false,"args":[{"name":"value","external_name":"value","restriction":""},{"name":"sql_type","external_name":"sql_type","restriction":""},{"name":"value_encoded","external_name":"value_encoded","restriction":""},{"name":"","external_name":"","restriction":""},{"name":"type_safe_value","default_value":"true","external_name":"type_safe_value","restriction":""}],"args_string":"(value, sql_type, value_encoded, *, type_safe_value = true)","args_html":"(value, sql_type, value_encoded, *, type_safe_value = true)","location":{"filename":"src/spec.cr","line_number":138,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L138"},"def":{"name":"sample_value","args":[{"name":"value","external_name":"value","restriction":""},{"name":"sql_type","external_name":"sql_type","restriction":""},{"name":"value_encoded","external_name":"value_encoded","restriction":""},{"name":"","external_name":"","restriction":""},{"name":"type_safe_value","default_value":"true","external_name":"type_safe_value","restriction":""}],"splat_index":3,"visibility":"Public","body":"@values << (ValueDef(DBAnyType).new(value, sql_type, value_encoded))\nit(\"select nil as (#{typeof(value)} | Nil)\", prepared: :both) do |db|\n db.query(select_scalar(encode_null, nil)) do |rs|\n assert_single_read(rs, typeof(value || nil), nil)\n end\nend\nvalue_desc = value.to_s\nif value_desc.size > 25\n value_desc = \"#{value_desc[0..25]}...(#{value_desc.size})\"\nend\nvalue_desc = \"#{value_desc} as #{sql_type}\"\nif type_safe_value\n it(\"executes with bind #{value_desc}\") do |db|\n (db.scalar(select_scalar(param(1), sql_type), value)).should(eq(value))\n end\n it(\"executes with bind #{value_desc} as array\") do |db|\n (db.scalar(select_scalar(param(1), sql_type), args: [value])).should(eq(value))\n end\n it(\"select #{value_desc} as literal\") do |db|\n (db.scalar(select_scalar(value_encoded, sql_type))).should(eq(value))\n db.query(select_scalar(value_encoded, sql_type)) do |rs|\n assert_single_read(rs, typeof(value), value)\n end\n end\nend\nit(\"insert/get value #{value_desc} from table\", prepared: :both) do |db|\n db.exec(sql_create_table_table1(c1 = col1(sql_type)))\n db.exec(sql_insert_table1(c1, value_encoded))\n (db.query_one(sql_select_table1(c1), as: typeof(value))).should(eq(value))\nend\nit(\"insert/get value #{value_desc} from table as nillable\", prepared: :both) do |db|\n db.exec(sql_create_table_table1(c1 = col1(sql_type)))\n db.exec(sql_insert_table1(c1, value_encoded))\n (db.query_one(sql_select_table1(c1), as: ::Union(typeof(value) | Nil))).should(eq(value))\nend\nit(\"insert/get value nil from table as nillable #{sql_type}\", prepared: :both) do |db|\n db.exec(sql_create_table_table1(c1 = col1(sql_type, null: true)))\n db.exec(sql_insert_table1(c1, encode_null))\n (db.query_one(sql_select_table1(c1), as: ::Union(typeof(value) | Nil))).should(eq(nil))\nend\nit(\"insert/get value #{value_desc} from table with binding\") do |db|\n db.exec(sql_create_table_table2(c1 = col1(sql_type_for(String)), c2 = col2(sql_type)))\n db.exec(sql_insert_table2(c1, param(1), c2, param(2)), value_for(String), value)\n (db.query_one(sql_select_table2(c2), as: typeof(value))).should(eq(value))\nend\nit(\"insert/get value #{value_desc} from table as nillable with binding\") do |db|\n db.exec(sql_create_table_table2(c1 = col1(sql_type_for(String)), c2 = col2(sql_type)))\n db.exec(sql_insert_table2(c1, param(1), c2, param(2)), value_for(String), value)\n (db.query_one(sql_select_table2(c2), as: ::Union(typeof(value) | Nil))).should(eq(value))\nend\nit(\"insert/get value nil from table as nillable #{sql_type} with binding\") do |db|\n db.exec(sql_create_table_table2(c1 = col1(sql_type_for(String)), c2 = col2(sql_type, null: true)))\n db.exec(sql_insert_table2(c1, param(1), c2, param(2)), value_for(String), nil)\n (db.query_one(sql_select_table2(c2), as: ::Union(typeof(value) | Nil))).should(eq(nil))\nend\nit(\"can use read(#{typeof(value)}) with DB::ResultSet\", prepared: :both) do |db|\n db.exec(sql_create_table_table1(c1 = col1(sql_type)))\n db.exec(sql_insert_table1(c1, value_encoded))\n db.query(sql_select_table1(c1)) do |rs|\n assert_single_read(rs.as(DB::ResultSet), typeof(value), value)\n end\nend\nit(\"can use read(#{typeof(value)}?) with DB::ResultSet\", prepared: :both) do |db|\n db.exec(sql_create_table_table1(c1 = col1(sql_type)))\n db.exec(sql_insert_table1(c1, value_encoded))\n db.query(sql_select_table1(c1)) do |rs|\n assert_single_read(rs.as(DB::ResultSet), ::Union(typeof(value) | Nil), value)\n end\nend\nit(\"can use read(#{typeof(value)}?) with DB::ResultSet for nil\", prepared: :both) do |db|\n db.exec(sql_create_table_table1(c1 = col1(sql_type, null: true)))\n db.exec(sql_insert_table1(c1, encode_null))\n db.query(sql_select_table1(c1)) do |rs|\n assert_single_read(rs.as(DB::ResultSet), ::Union(typeof(value) | Nil), nil)\n end\nend\n"}},{"html_id":"select_1column_syntax(&select_1column_syntax:Proc(String,ColumnDef,String))-instance-method","name":"select_1column_syntax","abstract":false,"location":{"filename":"src/spec.cr","line_number":116,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L116"},"def":{"name":"select_1column_syntax","yields":0,"block_arity":0,"block_arg":{"name":"select_1column_syntax","external_name":"select_1column_syntax","restriction":"Proc(String, ColumnDef, String)"},"visibility":"Public","body":"@select_1column_syntax = select_1column_syntax"}},{"html_id":"select_2columns_syntax(&select_2columns_syntax:Proc(String,ColumnDef,ColumnDef,String))-instance-method","name":"select_2columns_syntax","abstract":false,"location":{"filename":"src/spec.cr","line_number":117,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L117"},"def":{"name":"select_2columns_syntax","yields":0,"block_arity":0,"block_arg":{"name":"select_2columns_syntax","external_name":"select_2columns_syntax","restriction":"Proc(String, ColumnDef, ColumnDef, String)"},"visibility":"Public","body":"@select_2columns_syntax = select_2columns_syntax"}},{"html_id":"select_count_syntax(&select_count_syntax:Proc(String,String))-instance-method","name":"select_count_syntax","abstract":false,"location":{"filename":"src/spec.cr","line_number":118,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L118"},"def":{"name":"select_count_syntax","yields":0,"block_arity":0,"block_arg":{"name":"select_count_syntax","external_name":"select_count_syntax","restriction":"Proc(String, String)"},"visibility":"Public","body":"@select_count_syntax = select_count_syntax"}},{"html_id":"select_scalar_syntax(&select_scalar_syntax:Proc(String,String|Nil,String))-instance-method","name":"select_scalar_syntax","abstract":false,"location":{"filename":"src/spec.cr","line_number":111,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L111"},"def":{"name":"select_scalar_syntax","yields":0,"block_arity":0,"block_arg":{"name":"select_scalar_syntax","external_name":"select_scalar_syntax","restriction":"Proc(String, String | ::Nil, String)"},"visibility":"Public","body":"@select_scalar_syntax = select_scalar_syntax"}},{"html_id":"support_prepared(support_prepared:Bool)-instance-method","name":"support_prepared","doc":"Allow specs that uses prepared statements (default `true`)","summary":"

Allow specs that uses prepared statements (default true)

","abstract":false,"args":[{"name":"support_prepared","external_name":"support_prepared","restriction":"Bool"}],"args_string":"(support_prepared : Bool)","args_html":"(support_prepared : Bool)","location":{"filename":"src/spec.cr","line_number":70,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L70"},"def":{"name":"support_prepared","args":[{"name":"support_prepared","external_name":"support_prepared","restriction":"Bool"}],"visibility":"Public","body":"@support_prepared = support_prepared"}},{"html_id":"support_unprepared(support_unprepared:Bool)-instance-method","name":"support_unprepared","doc":"Allow specs that uses unprepared statements (default `true`)","summary":"

Allow specs that uses unprepared statements (default true)

","abstract":false,"args":[{"name":"support_unprepared","external_name":"support_unprepared","restriction":"Bool"}],"args_string":"(support_unprepared : Bool)","args_html":"(support_unprepared : Bool)","location":{"filename":"src/spec.cr","line_number":79,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L79"},"def":{"name":"support_unprepared","args":[{"name":"support_unprepared","external_name":"support_unprepared","restriction":"Bool"}],"visibility":"Public","body":"@support_unprepared = support_unprepared"}}],"types":[{"html_id":"db/DB/DriverSpecs/ColumnDef","path":"DB/DriverSpecs/ColumnDef.html","kind":"struct","full_name":"DB::DriverSpecs::ColumnDef","name":"ColumnDef","abstract":false,"superclass":{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/spec.cr","line_number":52,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L52"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB/DriverSpecs","kind":"class","full_name":"DB::DriverSpecs(DBAnyType)","name":"DriverSpecs"},"constructors":[{"html_id":"new(name:String,sql_type:String,null:Bool)-class-method","name":"new","abstract":false,"args":[{"name":"name","external_name":"name","restriction":"String"},{"name":"sql_type","external_name":"sql_type","restriction":"String"},{"name":"null","external_name":"null","restriction":"Bool"}],"args_string":"(name : String, sql_type : String, null : Bool)","args_html":"(name : String, sql_type : String, null : Bool)","location":{"filename":"src/spec.cr","line_number":52,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L52"},"def":{"name":"new","args":[{"name":"name","external_name":"name","restriction":"String"},{"name":"sql_type","external_name":"sql_type","restriction":"String"},{"name":"null","external_name":"null","restriction":"Bool"}],"visibility":"Public","body":"_ = allocate\n_.initialize(name, sql_type, null)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"clone-instance-method","name":"clone","abstract":false,"location":{"filename":"src/spec.cr","line_number":52,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L52"},"def":{"name":"clone","visibility":"Public","body":"self.class.new(@name.clone, @sql_type.clone, @null.clone)"}},{"html_id":"copy_with(name_name=@name,sql_type_sql_type=@sql_type,null_null=@null)-instance-method","name":"copy_with","abstract":false,"args":[{"name":"_name","default_value":"@name","external_name":"name","restriction":""},{"name":"_sql_type","default_value":"@sql_type","external_name":"sql_type","restriction":""},{"name":"_null","default_value":"@null","external_name":"null","restriction":""}],"args_string":"(name _name = @name, sql_type _sql_type = @sql_type, null _null = @null)","args_html":"(name _name = @name, sql_type _sql_type = @sql_type, null _null = @null)","location":{"filename":"src/spec.cr","line_number":52,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/spec.cr#L52"},"def":{"name":"copy_with","args":[{"name":"_name","default_value":"@name","external_name":"name","restriction":""},{"name":"_sql_type","default_value":"@sql_type","external_name":"sql_type","restriction":""},{"name":"_null","default_value":"@null","external_name":"null","restriction":""}],"visibility":"Public","body":"self.class.new(_name, _sql_type, _null)"}},{"html_id":"name:String-instance-method","name":"name","abstract":false,"def":{"name":"name","return_type":"String","visibility":"Public","body":"@name"}},{"html_id":"null:Bool-instance-method","name":"null","abstract":false,"def":{"name":"null","return_type":"Bool","visibility":"Public","body":"@null"}},{"html_id":"sql_type:String-instance-method","name":"sql_type","abstract":false,"def":{"name":"sql_type","return_type":"String","visibility":"Public","body":"@sql_type"}}]}]},{"html_id":"db/DB/Error","path":"DB/Error.html","kind":"class","full_name":"DB::Error","name":"Error","abstract":false,"superclass":{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":5,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L5"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"subclasses":[{"html_id":"db/DB/ColumnTypeMismatchError","kind":"class","full_name":"DB::ColumnTypeMismatchError","name":"ColumnTypeMismatchError"},{"html_id":"db/DB/MappingException","kind":"class","full_name":"DB::MappingException","name":"MappingException"},{"html_id":"db/DB/NoResultsError","kind":"class","full_name":"DB::NoResultsError","name":"NoResultsError"},{"html_id":"db/DB/PoolResourceLost","kind":"class","full_name":"DB::PoolResourceLost(T)","name":"PoolResourceLost"},{"html_id":"db/DB/PoolResourceRefused","kind":"class","full_name":"DB::PoolResourceRefused","name":"PoolResourceRefused"},{"html_id":"db/DB/PoolRetryAttemptsExceeded","kind":"class","full_name":"DB::PoolRetryAttemptsExceeded","name":"PoolRetryAttemptsExceeded"},{"html_id":"db/DB/PoolTimeout","kind":"class","full_name":"DB::PoolTimeout","name":"PoolTimeout"},{"html_id":"db/DB/Rollback","kind":"class","full_name":"DB::Rollback","name":"Rollback"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"}},{"html_id":"db/DB/ExecResult","path":"DB/ExecResult.html","kind":"struct","full_name":"DB::ExecResult","name":"ExecResult","abstract":false,"superclass":{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db.cr","line_number":96,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L96"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Result of a `#exec` statement.","summary":"

Result of a #exec statement.

","constructors":[{"html_id":"new(rows_affected:Int64,last_insert_id:Int64)-class-method","name":"new","abstract":false,"args":[{"name":"rows_affected","external_name":"rows_affected","restriction":"Int64"},{"name":"last_insert_id","external_name":"last_insert_id","restriction":"Int64"}],"args_string":"(rows_affected : Int64, last_insert_id : Int64)","args_html":"(rows_affected : Int64, last_insert_id : Int64)","location":{"filename":"src/db.cr","line_number":96,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L96"},"def":{"name":"new","args":[{"name":"rows_affected","external_name":"rows_affected","restriction":"Int64"},{"name":"last_insert_id","external_name":"last_insert_id","restriction":"Int64"}],"visibility":"Public","body":"_ = allocate\n_.initialize(rows_affected, last_insert_id)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"clone-instance-method","name":"clone","abstract":false,"location":{"filename":"src/db.cr","line_number":96,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L96"},"def":{"name":"clone","visibility":"Public","body":"self.class.new(@rows_affected.clone, @last_insert_id.clone)"}},{"html_id":"copy_with(rows_affected_rows_affected=@rows_affected,last_insert_id_last_insert_id=@last_insert_id)-instance-method","name":"copy_with","abstract":false,"args":[{"name":"_rows_affected","default_value":"@rows_affected","external_name":"rows_affected","restriction":""},{"name":"_last_insert_id","default_value":"@last_insert_id","external_name":"last_insert_id","restriction":""}],"args_string":"(rows_affected _rows_affected = @rows_affected, last_insert_id _last_insert_id = @last_insert_id)","args_html":"(rows_affected _rows_affected = @rows_affected, last_insert_id _last_insert_id = @last_insert_id)","location":{"filename":"src/db.cr","line_number":96,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db.cr#L96"},"def":{"name":"copy_with","args":[{"name":"_rows_affected","default_value":"@rows_affected","external_name":"rows_affected","restriction":""},{"name":"_last_insert_id","default_value":"@last_insert_id","external_name":"last_insert_id","restriction":""}],"visibility":"Public","body":"self.class.new(_rows_affected, _last_insert_id)"}},{"html_id":"last_insert_id:Int64-instance-method","name":"last_insert_id","abstract":false,"def":{"name":"last_insert_id","return_type":"Int64","visibility":"Public","body":"@last_insert_id"}},{"html_id":"rows_affected:Int64-instance-method","name":"rows_affected","abstract":false,"def":{"name":"rows_affected","return_type":"Int64","visibility":"Public","body":"@rows_affected"}}]},{"html_id":"db/DB/Field","path":"DB/Field.html","kind":"annotation","full_name":"DB::Field","name":"Field","abstract":false,"locations":[{"filename":"src/db/serializable.cr","line_number":2,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/serializable.cr#L2"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"}},{"html_id":"db/DB/Mappable","path":"DB/Mappable.html","kind":"module","full_name":"DB::Mappable","name":"Mappable","abstract":false,"locations":[{"filename":"src/db/mapping.cr","line_number":4,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/mapping.cr#L4"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Empty module used for marking a class as supporting DB:Mapping","summary":"

Empty module used for marking a class as supporting DB:Mapping

\n

DEPRECATED Use DB::Serializable instead

"},{"html_id":"db/DB/MappingException","path":"DB/MappingException.html","kind":"class","full_name":"DB::MappingException","name":"MappingException","abstract":false,"superclass":{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":8,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L8"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"constructors":[{"html_id":"new(message,klass:String,property:String|Nil=nil,cause:Exception|Nil=nil)-class-method","name":"new","abstract":false,"args":[{"name":"message","external_name":"message","restriction":""},{"name":"klass","external_name":"klass","restriction":"String"},{"name":"property","default_value":"nil","external_name":"property","restriction":"String | ::Nil"},{"name":"cause","default_value":"nil","external_name":"cause","restriction":"Exception | ::Nil"}],"args_string":"(message, klass : String, property : String | Nil = nil, cause : Exception | Nil = nil)","args_html":"(message, klass : String, property : String | Nil = nil, cause : Exception | Nil = nil)","location":{"filename":"src/db/error.cr","line_number":12,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L12"},"def":{"name":"new","args":[{"name":"message","external_name":"message","restriction":""},{"name":"klass","external_name":"klass","restriction":"String"},{"name":"property","default_value":"nil","external_name":"property","restriction":"String | ::Nil"},{"name":"cause","default_value":"nil","external_name":"cause","restriction":"Exception | ::Nil"}],"visibility":"Public","body":"_ = allocate\n_.initialize(message, klass, property, cause)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"klass:String-instance-method","name":"klass","abstract":false,"location":{"filename":"src/db/error.cr","line_number":9,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L9"},"def":{"name":"klass","visibility":"Public","body":"@klass"}},{"html_id":"property:String?-instance-method","name":"property","abstract":false,"location":{"filename":"src/db/error.cr","line_number":10,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L10"},"def":{"name":"property","visibility":"Public","body":"@property"}}]},{"html_id":"db/DB/MetadataValueConverter","path":"DB/MetadataValueConverter.html","kind":"module","full_name":"DB::MetadataValueConverter","name":"MetadataValueConverter","abstract":false,"locations":[{"filename":"src/db/statement.cr","line_number":172,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L172"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"This module converts DB supported values to `::Log::Metadata::Value`\n\n### Note to implementors\n\nIf the driver defines custom types to be used as arguments the default behavior\nwill be converting the value via `#to_s`. Otherwise you can define overloads to\nchange this behaviour.\n\n```\nmodule DB::MetadataValueConverter\n def self.arg_to_log(arg : PG::Geo::Point)\n ::Log::Metadata::Value.new(\"(#{arg.x}, #{arg.y})::point\")\n end\nend\n```","summary":"

This module converts DB supported values to ::Log::Metadata::Value

","class_methods":[{"html_id":"arg_to_log(arg:Enumerable):::Log::Metadata::Value-class-method","name":"arg_to_log","doc":"Returns *arg* encoded as a `::Log::Metadata::Value`.","summary":"

Returns arg encoded as a ::Log::Metadata::Value.

","abstract":false,"args":[{"name":"arg","external_name":"arg","restriction":"Enumerable"}],"args_string":"(arg : Enumerable) : ::Log::Metadata::Value","args_html":"(arg : Enumerable) : ::Log::Metadata::Value","location":{"filename":"src/db/statement.cr","line_number":179,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L179"},"def":{"name":"arg_to_log","args":[{"name":"arg","external_name":"arg","restriction":"Enumerable"}],"return_type":"::Log::Metadata::Value","visibility":"Public","body":"::Log::Metadata::Value.new(arg.to_a.map do |a|\n (arg_to_log(a)).as(::Log::Metadata::Value)\nend)"}},{"html_id":"arg_to_log(arg:UInt64):::Log::Metadata::Value-class-method","name":"arg_to_log","doc":"Returns *arg* encoded as a `::Log::Metadata::Value`.","summary":"

Returns arg encoded as a ::Log::Metadata::Value.

","abstract":false,"args":[{"name":"arg","external_name":"arg","restriction":"UInt64"}],"args_string":"(arg : UInt64) : ::Log::Metadata::Value","args_html":"(arg : UInt64) : ::Log::Metadata::Value","location":{"filename":"src/db/statement.cr","line_number":189,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L189"},"def":{"name":"arg_to_log","args":[{"name":"arg","external_name":"arg","restriction":"UInt64"}],"return_type":"::Log::Metadata::Value","visibility":"Public","body":"::Log::Metadata::Value.new(arg.to_s)"}},{"html_id":"arg_to_log(arg:Int):::Log::Metadata::Value-class-method","name":"arg_to_log","doc":"Returns *arg* encoded as a `::Log::Metadata::Value`.","summary":"

Returns arg encoded as a ::Log::Metadata::Value.

","abstract":false,"args":[{"name":"arg","external_name":"arg","restriction":"Int"}],"args_string":"(arg : Int) : ::Log::Metadata::Value","args_html":"(arg : Int) : ::Log::Metadata::Value","location":{"filename":"src/db/statement.cr","line_number":184,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L184"},"def":{"name":"arg_to_log","args":[{"name":"arg","external_name":"arg","restriction":"Int"}],"return_type":"::Log::Metadata::Value","visibility":"Public","body":"::Log::Metadata::Value.new(arg.to_i64)"}},{"html_id":"arg_to_log(arg:Nil|Bool|Int32|Int64|Float32|Float64|String|Time):::Log::Metadata::Value-class-method","name":"arg_to_log","doc":"Returns *arg* encoded as a `::Log::Metadata::Value`.","summary":"

Returns arg encoded as a ::Log::Metadata::Value.

","abstract":false,"args":[{"name":"arg","external_name":"arg","restriction":"Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Time"}],"args_string":"(arg : Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Time) : ::Log::Metadata::Value","args_html":"(arg : Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Time) : ::Log::Metadata::Value","location":{"filename":"src/db/statement.cr","line_number":194,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L194"},"def":{"name":"arg_to_log","args":[{"name":"arg","external_name":"arg","restriction":"Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Time"}],"return_type":"::Log::Metadata::Value","visibility":"Public","body":"::Log::Metadata::Value.new(arg)"}},{"html_id":"arg_to_log(arg):::Log::Metadata::Value-class-method","name":"arg_to_log","doc":"Returns *arg* encoded as a `::Log::Metadata::Value`.","summary":"

Returns arg encoded as a ::Log::Metadata::Value.

","abstract":false,"args":[{"name":"arg","external_name":"arg","restriction":""}],"args_string":"(arg) : ::Log::Metadata::Value","args_html":"(arg) : ::Log::Metadata::Value","location":{"filename":"src/db/statement.cr","line_number":174,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L174"},"def":{"name":"arg_to_log","args":[{"name":"arg","external_name":"arg","restriction":""}],"return_type":"::Log::Metadata::Value","visibility":"Public","body":"::Log::Metadata::Value.new(arg.to_s)"}}]},{"html_id":"db/DB/NoResultsError","path":"DB/NoResultsError.html","kind":"class","full_name":"DB::NoResultsError","name":"NoResultsError","abstract":false,"superclass":{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":61,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L61"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Raised when a scalar query returns no results.","summary":"

Raised when a scalar query returns no results.

"},{"html_id":"db/DB/Pool","path":"DB/Pool.html","kind":"class","full_name":"DB::Pool(T)","name":"Pool","abstract":false,"superclass":{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/pool.cr","line_number":6,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L6"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"constructors":[{"html_id":"new(pool_options:Options=Options.new,&factory:->T)-class-method","name":"new","abstract":false,"args":[{"name":"pool_options","default_value":"Options.new","external_name":"pool_options","restriction":"Options"}],"args_string":"(pool_options : Options = Options.new, &factory : -> T)","args_html":"(pool_options : Options = Options.new, &factory : -> T)","location":{"filename":"src/db/pool.cr","line_number":74,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L74"},"def":{"name":"new","args":[{"name":"pool_options","default_value":"Options.new","external_name":"pool_options","restriction":"Options"}],"yields":0,"block_arity":0,"block_arg":{"name":"factory","external_name":"factory","restriction":"(-> T)"},"visibility":"Public","body":"_ = Pool(T).allocate\n_.initialize(pool_options, &factory) do\n yield\nend\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new(initial_pool_size=1,max_pool_size=0,max_idle_pool_size=1,checkout_timeout=5.0,retry_attempts=1,retry_delay=0.2,&factory:->T)-class-method","name":"new","summary":"

DEPRECATED Use #new with DB::Pool::Options instead

","abstract":false,"args":[{"name":"initial_pool_size","default_value":"1","external_name":"initial_pool_size","restriction":""},{"name":"max_pool_size","default_value":"0","external_name":"max_pool_size","restriction":""},{"name":"max_idle_pool_size","default_value":"1","external_name":"max_idle_pool_size","restriction":""},{"name":"checkout_timeout","default_value":"5.0","external_name":"checkout_timeout","restriction":""},{"name":"retry_attempts","default_value":"1","external_name":"retry_attempts","restriction":""},{"name":"retry_delay","default_value":"0.2","external_name":"retry_delay","restriction":""}],"args_string":"(initial_pool_size = 1, max_pool_size = 0, max_idle_pool_size = 1, checkout_timeout = 5.0, retry_attempts = 1, retry_delay = 0.2, &factory : -> T)","args_html":"(initial_pool_size = 1, max_pool_size = 0, max_idle_pool_size = 1, checkout_timeout = 5.0, retry_attempts = 1, retry_delay = 0.2, &factory : -> T)","location":{"filename":"src/db/pool.cr","line_number":64,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L64"},"def":{"name":"new","args":[{"name":"initial_pool_size","default_value":"1","external_name":"initial_pool_size","restriction":""},{"name":"max_pool_size","default_value":"0","external_name":"max_pool_size","restriction":""},{"name":"max_idle_pool_size","default_value":"1","external_name":"max_idle_pool_size","restriction":""},{"name":"checkout_timeout","default_value":"5.0","external_name":"checkout_timeout","restriction":""},{"name":"retry_attempts","default_value":"1","external_name":"retry_attempts","restriction":""},{"name":"retry_delay","default_value":"0.2","external_name":"retry_delay","restriction":""}],"yields":0,"block_arity":0,"block_arg":{"name":"factory","external_name":"factory","restriction":"(-> T)"},"visibility":"Public","body":"_ = Pool(T).allocate\n_.initialize(initial_pool_size, max_pool_size, max_idle_pool_size, checkout_timeout, retry_attempts, retry_delay, &factory) do\n yield\nend\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"checkout:T-instance-method","name":"checkout","abstract":false,"location":{"filename":"src/db/pool.cr","line_number":112,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L112"},"def":{"name":"checkout","return_type":"T","visibility":"Public","body":"res = sync do\n resource = nil\n while !resource\n resource = if @idle.empty?\n if can_increase_pool?\n @inflight = @inflight + 1\n begin\n r = unsync do\n build_resource\n end\n ensure\n @inflight = @inflight - 1\n end\n r\n else\n unsync do\n wait_for_available\n end\n pick_available\n end\n else\n pick_available\n end\n end\n @idle.delete(resource)\n resource\nend\nif res.responds_to?(:before_checkout)\n res.before_checkout\nend\nres\n"}},{"html_id":"checkout(&block:T->)-instance-method","name":"checkout","abstract":false,"location":{"filename":"src/db/pool.cr","line_number":151,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L151"},"def":{"name":"checkout","yields":1,"block_arity":1,"block_arg":{"name":"block","external_name":"block","restriction":"(T ->)"},"visibility":"Public","body":"connection = checkout\nbegin\n yield connection\nensure\n release(connection)\nend\n"}},{"html_id":"close:Nil-instance-method","name":"close","doc":"close all resources in the pool","summary":"

close all resources in the pool

","abstract":false,"location":{"filename":"src/db/pool.cr","line_number":90,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L90"},"def":{"name":"close","return_type":"Nil","visibility":"Public","body":"@total.each(&.close)\n@total.clear\n@idle.clear\n"}},{"html_id":"release(resource:T):Nil-instance-method","name":"release","abstract":false,"args":[{"name":"resource","external_name":"resource","restriction":"T"}],"args_string":"(resource : T) : Nil","args_html":"(resource : T) : Nil","location":{"filename":"src/db/pool.cr","line_number":161,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L161"},"def":{"name":"release","args":[{"name":"resource","external_name":"resource","restriction":"T"}],"return_type":"Nil","visibility":"Public","body":"idle_pushed = false\nsync do\n if (resource.responds_to?(:\"closed?\")) && resource.closed?\n @total.delete(resource)\n else\n if can_increase_idle_pool\n @idle << resource\n if resource.responds_to?(:after_release)\n resource.after_release\n end\n idle_pushed = true\n else\n resource.close\n @total.delete(resource)\n end\n end\nend\nif idle_pushed\n select\nwhen @availability_channel.send(nil)\nelse\nend\n\nend\n"}},{"html_id":"stats-instance-method","name":"stats","doc":"Returns stats of the pool","summary":"

Returns stats of the pool

","abstract":false,"location":{"filename":"src/db/pool.cr","line_number":103,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L103"},"def":{"name":"stats","visibility":"Public","body":"Stats.new(open_connections: @total.size, idle_connections: @idle.size, in_flight_connections: @inflight, max_connections: @max_pool_size)"}}],"types":[{"html_id":"db/DB/Pool/Options","path":"DB/Pool/Options.html","kind":"struct","full_name":"DB::Pool::Options","name":"Options","abstract":false,"superclass":{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/pool.cr","line_number":7,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L7"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB/Pool","kind":"class","full_name":"DB::Pool(T)","name":"Pool"},"class_methods":[{"html_id":"from_http_params(params:HTTP::Params,default=Options.new)-class-method","name":"from_http_params","abstract":false,"args":[{"name":"params","external_name":"params","restriction":"HTTP::Params"},{"name":"default","default_value":"Options.new","external_name":"default","restriction":""}],"args_string":"(params : HTTP::Params, default = Options.new)","args_html":"(params : HTTP::Params, default = Options.new)","location":{"filename":"src/db/pool.cr","line_number":20,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L20"},"def":{"name":"from_http_params","args":[{"name":"params","external_name":"params","restriction":"HTTP::Params"},{"name":"default","default_value":"Options.new","external_name":"default","restriction":""}],"visibility":"Public","body":"Options.new(initial_pool_size: (params.fetch(\"initial_pool_size\", default.initial_pool_size)).to_i, max_pool_size: (params.fetch(\"max_pool_size\", default.max_pool_size)).to_i, max_idle_pool_size: (params.fetch(\"max_idle_pool_size\", default.max_idle_pool_size)).to_i, checkout_timeout: (params.fetch(\"checkout_timeout\", default.checkout_timeout)).to_f, retry_attempts: (params.fetch(\"retry_attempts\", default.retry_attempts)).to_i, retry_delay: (params.fetch(\"retry_delay\", default.retry_delay)).to_f)"}}],"constructors":[{"html_id":"new(initial_pool_size:Int32=1,max_pool_size:Int32=0,max_idle_pool_size:Int32=1,checkout_timeout:Float64=5.0,retry_attempts:Int32=1,retry_delay:Float64=0.2)-class-method","name":"new","abstract":false,"args":[{"name":"initial_pool_size","default_value":"1","external_name":"initial_pool_size","restriction":"Int32"},{"name":"max_pool_size","default_value":"0","external_name":"max_pool_size","restriction":"Int32"},{"name":"max_idle_pool_size","default_value":"1","external_name":"max_idle_pool_size","restriction":"Int32"},{"name":"checkout_timeout","default_value":"5.0","external_name":"checkout_timeout","restriction":"Float64"},{"name":"retry_attempts","default_value":"1","external_name":"retry_attempts","restriction":"Int32"},{"name":"retry_delay","default_value":"0.2","external_name":"retry_delay","restriction":"Float64"}],"args_string":"(initial_pool_size : Int32 = 1, max_pool_size : Int32 = 0, max_idle_pool_size : Int32 = 1, checkout_timeout : Float64 = 5.0, retry_attempts : Int32 = 1, retry_delay : Float64 = 0.2)","args_html":"(initial_pool_size : Int32 = 1, max_pool_size : Int32 = 0, max_idle_pool_size : Int32 = 1, checkout_timeout : Float64 = 5.0, retry_attempts : Int32 = 1, retry_delay : Float64 = 0.2)","location":{"filename":"src/db/pool.cr","line_number":7,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L7"},"def":{"name":"new","args":[{"name":"initial_pool_size","default_value":"1","external_name":"initial_pool_size","restriction":"Int32"},{"name":"max_pool_size","default_value":"0","external_name":"max_pool_size","restriction":"Int32"},{"name":"max_idle_pool_size","default_value":"1","external_name":"max_idle_pool_size","restriction":"Int32"},{"name":"checkout_timeout","default_value":"5.0","external_name":"checkout_timeout","restriction":"Float64"},{"name":"retry_attempts","default_value":"1","external_name":"retry_attempts","restriction":"Int32"},{"name":"retry_delay","default_value":"0.2","external_name":"retry_delay","restriction":"Float64"}],"visibility":"Public","body":"_ = allocate\n_.initialize(initial_pool_size, max_pool_size, max_idle_pool_size, checkout_timeout, retry_attempts, retry_delay)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"checkout_timeout:Float64-instance-method","name":"checkout_timeout","abstract":false,"def":{"name":"checkout_timeout","return_type":"Float64","visibility":"Public","body":"@checkout_timeout"}},{"html_id":"clone-instance-method","name":"clone","abstract":false,"location":{"filename":"src/db/pool.cr","line_number":7,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L7"},"def":{"name":"clone","visibility":"Public","body":"self.class.new(@initial_pool_size.clone, @max_pool_size.clone, @max_idle_pool_size.clone, @checkout_timeout.clone, @retry_attempts.clone, @retry_delay.clone)"}},{"html_id":"copy_with(initial_pool_size_initial_pool_size=@initial_pool_size,max_pool_size_max_pool_size=@max_pool_size,max_idle_pool_size_max_idle_pool_size=@max_idle_pool_size,checkout_timeout_checkout_timeout=@checkout_timeout,retry_attempts_retry_attempts=@retry_attempts,retry_delay_retry_delay=@retry_delay)-instance-method","name":"copy_with","abstract":false,"args":[{"name":"_initial_pool_size","default_value":"@initial_pool_size","external_name":"initial_pool_size","restriction":""},{"name":"_max_pool_size","default_value":"@max_pool_size","external_name":"max_pool_size","restriction":""},{"name":"_max_idle_pool_size","default_value":"@max_idle_pool_size","external_name":"max_idle_pool_size","restriction":""},{"name":"_checkout_timeout","default_value":"@checkout_timeout","external_name":"checkout_timeout","restriction":""},{"name":"_retry_attempts","default_value":"@retry_attempts","external_name":"retry_attempts","restriction":""},{"name":"_retry_delay","default_value":"@retry_delay","external_name":"retry_delay","restriction":""}],"args_string":"(initial_pool_size _initial_pool_size = @initial_pool_size, max_pool_size _max_pool_size = @max_pool_size, max_idle_pool_size _max_idle_pool_size = @max_idle_pool_size, checkout_timeout _checkout_timeout = @checkout_timeout, retry_attempts _retry_attempts = @retry_attempts, retry_delay _retry_delay = @retry_delay)","args_html":"(initial_pool_size _initial_pool_size = @initial_pool_size, max_pool_size _max_pool_size = @max_pool_size, max_idle_pool_size _max_idle_pool_size = @max_idle_pool_size, checkout_timeout _checkout_timeout = @checkout_timeout, retry_attempts _retry_attempts = @retry_attempts, retry_delay _retry_delay = @retry_delay)","location":{"filename":"src/db/pool.cr","line_number":7,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L7"},"def":{"name":"copy_with","args":[{"name":"_initial_pool_size","default_value":"@initial_pool_size","external_name":"initial_pool_size","restriction":""},{"name":"_max_pool_size","default_value":"@max_pool_size","external_name":"max_pool_size","restriction":""},{"name":"_max_idle_pool_size","default_value":"@max_idle_pool_size","external_name":"max_idle_pool_size","restriction":""},{"name":"_checkout_timeout","default_value":"@checkout_timeout","external_name":"checkout_timeout","restriction":""},{"name":"_retry_attempts","default_value":"@retry_attempts","external_name":"retry_attempts","restriction":""},{"name":"_retry_delay","default_value":"@retry_delay","external_name":"retry_delay","restriction":""}],"visibility":"Public","body":"self.class.new(_initial_pool_size, _max_pool_size, _max_idle_pool_size, _checkout_timeout, _retry_attempts, _retry_delay)"}},{"html_id":"initial_pool_size:Int32-instance-method","name":"initial_pool_size","abstract":false,"def":{"name":"initial_pool_size","return_type":"Int32","visibility":"Public","body":"@initial_pool_size"}},{"html_id":"max_idle_pool_size:Int32-instance-method","name":"max_idle_pool_size","abstract":false,"def":{"name":"max_idle_pool_size","return_type":"Int32","visibility":"Public","body":"@max_idle_pool_size"}},{"html_id":"max_pool_size:Int32-instance-method","name":"max_pool_size","abstract":false,"def":{"name":"max_pool_size","return_type":"Int32","visibility":"Public","body":"@max_pool_size"}},{"html_id":"retry_attempts:Int32-instance-method","name":"retry_attempts","abstract":false,"def":{"name":"retry_attempts","return_type":"Int32","visibility":"Public","body":"@retry_attempts"}},{"html_id":"retry_delay:Float64-instance-method","name":"retry_delay","abstract":false,"def":{"name":"retry_delay","return_type":"Float64","visibility":"Public","body":"@retry_delay"}}]},{"html_id":"db/DB/Pool/Stats","path":"DB/Pool/Stats.html","kind":"struct","full_name":"DB::Pool::Stats","name":"Stats","abstract":false,"superclass":{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/pool.cr","line_number":96,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L96"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB/Pool","kind":"class","full_name":"DB::Pool(T)","name":"Pool"},"constructors":[{"html_id":"new(open_connections:Int32,idle_connections:Int32,in_flight_connections:Int32,max_connections:Int32)-class-method","name":"new","abstract":false,"args":[{"name":"open_connections","external_name":"open_connections","restriction":"Int32"},{"name":"idle_connections","external_name":"idle_connections","restriction":"Int32"},{"name":"in_flight_connections","external_name":"in_flight_connections","restriction":"Int32"},{"name":"max_connections","external_name":"max_connections","restriction":"Int32"}],"args_string":"(open_connections : Int32, idle_connections : Int32, in_flight_connections : Int32, max_connections : Int32)","args_html":"(open_connections : Int32, idle_connections : Int32, in_flight_connections : Int32, max_connections : Int32)","location":{"filename":"src/db/pool.cr","line_number":96,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L96"},"def":{"name":"new","args":[{"name":"open_connections","external_name":"open_connections","restriction":"Int32"},{"name":"idle_connections","external_name":"idle_connections","restriction":"Int32"},{"name":"in_flight_connections","external_name":"in_flight_connections","restriction":"Int32"},{"name":"max_connections","external_name":"max_connections","restriction":"Int32"}],"visibility":"Public","body":"_ = allocate\n_.initialize(open_connections, idle_connections, in_flight_connections, max_connections)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"clone-instance-method","name":"clone","abstract":false,"location":{"filename":"src/db/pool.cr","line_number":96,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L96"},"def":{"name":"clone","visibility":"Public","body":"self.class.new(@open_connections.clone, @idle_connections.clone, @in_flight_connections.clone, @max_connections.clone)"}},{"html_id":"copy_with(open_connections_open_connections=@open_connections,idle_connections_idle_connections=@idle_connections,in_flight_connections_in_flight_connections=@in_flight_connections,max_connections_max_connections=@max_connections)-instance-method","name":"copy_with","abstract":false,"args":[{"name":"_open_connections","default_value":"@open_connections","external_name":"open_connections","restriction":""},{"name":"_idle_connections","default_value":"@idle_connections","external_name":"idle_connections","restriction":""},{"name":"_in_flight_connections","default_value":"@in_flight_connections","external_name":"in_flight_connections","restriction":""},{"name":"_max_connections","default_value":"@max_connections","external_name":"max_connections","restriction":""}],"args_string":"(open_connections _open_connections = @open_connections, idle_connections _idle_connections = @idle_connections, in_flight_connections _in_flight_connections = @in_flight_connections, max_connections _max_connections = @max_connections)","args_html":"(open_connections _open_connections = @open_connections, idle_connections _idle_connections = @idle_connections, in_flight_connections _in_flight_connections = @in_flight_connections, max_connections _max_connections = @max_connections)","location":{"filename":"src/db/pool.cr","line_number":96,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool.cr#L96"},"def":{"name":"copy_with","args":[{"name":"_open_connections","default_value":"@open_connections","external_name":"open_connections","restriction":""},{"name":"_idle_connections","default_value":"@idle_connections","external_name":"idle_connections","restriction":""},{"name":"_in_flight_connections","default_value":"@in_flight_connections","external_name":"in_flight_connections","restriction":""},{"name":"_max_connections","default_value":"@max_connections","external_name":"max_connections","restriction":""}],"visibility":"Public","body":"self.class.new(_open_connections, _idle_connections, _in_flight_connections, _max_connections)"}},{"html_id":"idle_connections:Int32-instance-method","name":"idle_connections","abstract":false,"def":{"name":"idle_connections","return_type":"Int32","visibility":"Public","body":"@idle_connections"}},{"html_id":"in_flight_connections:Int32-instance-method","name":"in_flight_connections","abstract":false,"def":{"name":"in_flight_connections","return_type":"Int32","visibility":"Public","body":"@in_flight_connections"}},{"html_id":"max_connections:Int32-instance-method","name":"max_connections","abstract":false,"def":{"name":"max_connections","return_type":"Int32","visibility":"Public","body":"@max_connections"}},{"html_id":"open_connections:Int32-instance-method","name":"open_connections","abstract":false,"def":{"name":"open_connections","return_type":"Int32","visibility":"Public","body":"@open_connections"}}]}]},{"html_id":"db/DB/PoolPreparedStatement","path":"DB/PoolPreparedStatement.html","kind":"struct","full_name":"DB::PoolPreparedStatement","name":"PoolPreparedStatement","abstract":false,"superclass":{"html_id":"db/DB/PoolStatement","kind":"struct","full_name":"DB::PoolStatement","name":"PoolStatement"},"ancestors":[{"html_id":"db/DB/PoolStatement","kind":"struct","full_name":"DB::PoolStatement","name":"PoolStatement"},{"html_id":"db/DB/StatementMethods","kind":"module","full_name":"DB::StatementMethods","name":"StatementMethods"},{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/pool_prepared_statement.cr","line_number":7,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_prepared_statement.cr#L7"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Represents a statement to be executed in any of the connections\nof the pool. The statement is not be executed in a prepared fashion.\nThe execution of the statement is retried according to the pool configuration.\n\nSee `PoolStatement`","summary":"

Represents a statement to be executed in any of the connections of the pool.

","constructors":[{"html_id":"new(db:Database,query:String)-class-method","name":"new","abstract":false,"args":[{"name":"db","external_name":"db","restriction":"Database"},{"name":"query","external_name":"query","restriction":"String"}],"args_string":"(db : Database, query : String)","args_html":"(db : Database, query : String)","location":{"filename":"src/db/pool_prepared_statement.cr","line_number":8,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_prepared_statement.cr#L8"},"def":{"name":"new","args":[{"name":"db","external_name":"db","restriction":"Database"},{"name":"query","external_name":"query","restriction":"String"}],"visibility":"Public","body":"_ = allocate\n_.initialize(db, query)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}]},{"html_id":"db/DB/PoolResourceLost","path":"DB/PoolResourceLost.html","kind":"class","full_name":"DB::PoolResourceLost(T)","name":"PoolResourceLost","abstract":false,"superclass":{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":30,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L30"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"subclasses":[{"html_id":"db/DB/ConnectionLost","kind":"class","full_name":"DB::ConnectionLost","name":"ConnectionLost"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"constructors":[{"html_id":"new(resource:T,cause:Exception|Nil=nil)-class-method","name":"new","abstract":false,"args":[{"name":"resource","external_name":"resource","restriction":"T"},{"name":"cause","default_value":"nil","external_name":"cause","restriction":"Exception | ::Nil"}],"args_string":"(resource : T, cause : Exception | Nil = nil)","args_html":"(resource : T, cause : Exception | Nil = nil)","location":{"filename":"src/db/error.cr","line_number":33,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L33"},"def":{"name":"new","args":[{"name":"resource","external_name":"resource","restriction":"T"},{"name":"cause","default_value":"nil","external_name":"cause","restriction":"Exception | ::Nil"}],"visibility":"Public","body":"_ = PoolResourceLost(T).allocate\n_.initialize(resource, cause)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"resource:T-instance-method","name":"resource","abstract":false,"location":{"filename":"src/db/error.cr","line_number":31,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L31"},"def":{"name":"resource","return_type":"T","visibility":"Public","body":"@resource"}}]},{"html_id":"db/DB/PoolResourceRefused","path":"DB/PoolResourceRefused.html","kind":"class","full_name":"DB::PoolResourceRefused","name":"PoolResourceRefused","abstract":false,"superclass":{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":39,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L39"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"subclasses":[{"html_id":"db/DB/ConnectionRefused","kind":"class","full_name":"DB::ConnectionRefused","name":"ConnectionRefused"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"}},{"html_id":"db/DB/PoolRetryAttemptsExceeded","path":"DB/PoolRetryAttemptsExceeded.html","kind":"class","full_name":"DB::PoolRetryAttemptsExceeded","name":"PoolRetryAttemptsExceeded","abstract":false,"superclass":{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":27,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L27"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"}},{"html_id":"db/DB/PoolStatement","path":"DB/PoolStatement.html","kind":"struct","full_name":"DB::PoolStatement","name":"PoolStatement","abstract":true,"superclass":{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"db/DB/StatementMethods","kind":"module","full_name":"DB::StatementMethods","name":"StatementMethods"},{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/pool_statement.cr","line_number":6,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_statement.cr#L6"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/DB/StatementMethods","kind":"module","full_name":"DB::StatementMethods","name":"StatementMethods"}],"subclasses":[{"html_id":"db/DB/PoolPreparedStatement","kind":"struct","full_name":"DB::PoolPreparedStatement","name":"PoolPreparedStatement"},{"html_id":"db/DB/PoolUnpreparedStatement","kind":"struct","full_name":"DB::PoolUnpreparedStatement","name":"PoolUnpreparedStatement"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"When a statement is to be executed in a DB that has a connection pool\na statement from the DB needs to be able to represent a statement in any\nof the connections of the pool. Otherwise the user will need to deal with\nactual connections in some point.","summary":"

When a statement is to be executed in a DB that has a connection pool a statement from the DB needs to be able to represent a statement in any of the connections of the pool.

","constructors":[{"html_id":"new(db:Database,query:String)-class-method","name":"new","abstract":false,"args":[{"name":"db","external_name":"db","restriction":"Database"},{"name":"query","external_name":"query","restriction":"String"}],"args_string":"(db : Database, query : String)","args_html":"(db : Database, query : String)","location":{"filename":"src/db/pool_statement.cr","line_number":9,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_statement.cr#L9"},"def":{"name":"new","args":[{"name":"db","external_name":"db","restriction":"Database"},{"name":"query","external_name":"query","restriction":"String"}],"visibility":"Public","body":"_ = allocate\n_.initialize(db, query)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"exec:ExecResult-instance-method","name":"exec","doc":"See `QueryMethods#exec`","summary":"

See QueryMethods#exec

","abstract":false,"location":{"filename":"src/db/pool_statement.cr","line_number":13,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_statement.cr#L13"},"def":{"name":"exec","return_type":"ExecResult","visibility":"Public","body":"statement_with_retry(&.exec)"}},{"html_id":"exec(*args_,args:Array|Nil=nil):ExecResult-instance-method","name":"exec","doc":"See `QueryMethods#exec`","summary":"

See QueryMethods#exec

","abstract":false,"args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(*args_, args : Array | Nil = nil) : ExecResult","args_html":"(*args_, args : Array | Nil = nil) : ExecResult","location":{"filename":"src/db/pool_statement.cr","line_number":18,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_statement.cr#L18"},"def":{"name":"exec","args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":0,"return_type":"ExecResult","visibility":"Public","body":"statement_with_retry(&.exec(*args_, args: args))"}},{"html_id":"query:ResultSet-instance-method","name":"query","doc":"See `QueryMethods#query`","summary":"

See QueryMethods#query

","abstract":false,"location":{"filename":"src/db/pool_statement.cr","line_number":23,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_statement.cr#L23"},"def":{"name":"query","return_type":"ResultSet","visibility":"Public","body":"statement_with_retry(&.query)"}},{"html_id":"query(*args_,args:Array|Nil=nil):ResultSet-instance-method","name":"query","doc":"See `QueryMethods#query`","summary":"

See QueryMethods#query

","abstract":false,"args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(*args_, args : Array | Nil = nil) : ResultSet","args_html":"(*args_, args : Array | Nil = nil) : ResultSet","location":{"filename":"src/db/pool_statement.cr","line_number":28,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_statement.cr#L28"},"def":{"name":"query","args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":0,"return_type":"ResultSet","visibility":"Public","body":"statement_with_retry(&.query(*args_, args: args))"}},{"html_id":"scalar(*args_,args:Array|Nil=nil)-instance-method","name":"scalar","doc":"See `QueryMethods#scalar`","summary":"

See QueryMethods#scalar

","abstract":false,"args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(*args_, args : Array | Nil = nil)","args_html":"(*args_, args : Array | Nil = nil)","location":{"filename":"src/db/pool_statement.cr","line_number":33,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_statement.cr#L33"},"def":{"name":"scalar","args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":0,"visibility":"Public","body":"statement_with_retry(&.scalar(*args_, args: args))"}}]},{"html_id":"db/DB/PoolTimeout","path":"DB/PoolTimeout.html","kind":"class","full_name":"DB::PoolTimeout","name":"PoolTimeout","abstract":false,"superclass":{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":24,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L24"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"}},{"html_id":"db/DB/PoolUnpreparedStatement","path":"DB/PoolUnpreparedStatement.html","kind":"struct","full_name":"DB::PoolUnpreparedStatement","name":"PoolUnpreparedStatement","abstract":false,"superclass":{"html_id":"db/DB/PoolStatement","kind":"struct","full_name":"DB::PoolStatement","name":"PoolStatement"},"ancestors":[{"html_id":"db/DB/PoolStatement","kind":"struct","full_name":"DB::PoolStatement","name":"PoolStatement"},{"html_id":"db/DB/StatementMethods","kind":"module","full_name":"DB::StatementMethods","name":"StatementMethods"},{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/pool_unprepared_statement.cr","line_number":7,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_unprepared_statement.cr#L7"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Represents a statement to be executed in any of the connections\nof the pool. The statement is not be executed in a non prepared fashion.\nThe execution of the statement is retried according to the pool configuration.\n\nSee `PoolStatement`","summary":"

Represents a statement to be executed in any of the connections of the pool.

","constructors":[{"html_id":"new(db:Database,query:String)-class-method","name":"new","abstract":false,"args":[{"name":"db","external_name":"db","restriction":"Database"},{"name":"query","external_name":"query","restriction":"String"}],"args_string":"(db : Database, query : String)","args_html":"(db : Database, query : String)","location":{"filename":"src/db/pool_unprepared_statement.cr","line_number":8,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/pool_unprepared_statement.cr#L8"},"def":{"name":"new","args":[{"name":"db","external_name":"db","restriction":"Database"},{"name":"query","external_name":"query","restriction":"String"}],"visibility":"Public","body":"_ = allocate\n_.initialize(db, query)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}]},{"html_id":"db/DB/QueryMethods","path":"DB/QueryMethods.html","kind":"module","full_name":"DB::QueryMethods(Stmt)","name":"QueryMethods","abstract":false,"locations":[{"filename":"src/db/query_methods.cr","line_number":21,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L21"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"including_types":[{"html_id":"db/DB/SessionMethods","kind":"module","full_name":"DB::SessionMethods(Session, Stmt)","name":"SessionMethods"},{"html_id":"db/DB/SessionMethods/PreparedQuery","kind":"struct","full_name":"DB::SessionMethods::PreparedQuery(Session, Stmt)","name":"PreparedQuery"},{"html_id":"db/DB/SessionMethods/UnpreparedQuery","kind":"struct","full_name":"DB::SessionMethods::UnpreparedQuery(Session, Stmt)","name":"UnpreparedQuery"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Methods to allow querying a database.\nAll methods accepts a `query : String` and a set arguments.\n\nThree kind of statements can be performed:\n 1. `#exec` waits no record response from the database. An `ExecResult` is returned.\n 2. `#scalar` reads a single value of the response. A union of possible values is returned.\n 3. `#query` returns a `ResultSet` that allows iteration over the rows in the response and column information.\n\nArguments can be passed by position or as an array.\n\n```\ndb.query(\"SELECT name FROM ... WHERE age > ?\", age)\ndb.query(\"SELECT name FROM ... WHERE age > ?\", args: [age])\n```\n\nConvention of mapping how arguments are mapped to the query depends on each driver.\n\nIncluding `QueryMethods` requires a `build(query) : Statement` method that is not expected\nto be called directly.","summary":"

Methods to allow querying a database.

","instance_methods":[{"html_id":"exec(query,*args_,args:Array|Nil=nil)-instance-method","name":"exec","doc":"Performs the `query` and returns an `ExecResult`","summary":"

Performs the #query and returns an ExecResult

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(query, *args_, args : Array | Nil = nil)","args_html":"(query, *args_, args : Array | Nil = nil)","location":{"filename":"src/db/query_methods.cr","line_number":274,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L274"},"def":{"name":"exec","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":1,"visibility":"Public","body":"(build(query)).exec(*args_, args: args)"}},{"html_id":"query(query,*args_,args:Array|Nil=nil)-instance-method","name":"query","doc":"Executes a *query* and returns a `ResultSet` with the results.\nThe `ResultSet` must be closed manually.\n\n```\nresult = db.query \"select name from contacts where id = ?\", 10\nbegin\n if result.move_next\n id = result.read(Int32)\n end\nensure\n result.close\nend\n```\n\nNote: to use a dynamic list length of arguments use `args:` keyword argument.\n\n```\nresult = db.query \"select name from contacts where id = ?\", args: [10]\n```\n","summary":"

Executes a query and returns a ResultSet with the results.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(query, *args_, args : Array | Nil = nil)","args_html":"(query, *args_, args : Array | Nil = nil)","location":{"filename":"src/db/query_methods.cr","line_number":45,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L45"},"def":{"name":"query","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":1,"visibility":"Public","body":"(build(query)).query(*args_, args: args)"}},{"html_id":"query(query,*args_,args:Array|Nil=nil,&)-instance-method","name":"query","doc":"Executes a *query* and yields a `ResultSet` with the results.\nThe `ResultSet` is closed automatically.\n\n```\ndb.query(\"select name from contacts where age > ?\", 18) do |rs|\n rs.each do\n name = rs.read(String)\n end\nend\n```","summary":"

Executes a query and yields a ResultSet with the results.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(query, *args_, args : Array | Nil = nil, &)","args_html":"(query, *args_, args : Array | Nil = nil, &)","location":{"filename":"src/db/query_methods.cr","line_number":59,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L59"},"def":{"name":"query","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":1,"yields":1,"block_arity":1,"visibility":"Public","body":"rs = query(query, *args_, args: args)\nbegin\n yield rs\nensure\n rs.close\nend\n"}},{"html_id":"query_all(query,*args_,args:Array|Nil=nil,&block:ResultSet->U):Array(U)forallU-instance-method","name":"query_all","doc":"Executes a *query* and yield a `ResultSet` positioned at the beginning\nof each row, returning an array of the values of the blocks.\n\n```\nnames = db.query_all \"select name from contacts\", &.read(String)\n```","summary":"

Executes a query and yield a ResultSet positioned at the beginning of each row, returning an array of the values of the blocks.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(query, *args_, args : Array | Nil = nil, &block : ResultSet -> U) : Array(U) forall U","args_html":"(query, *args_, args : Array | Nil = nil, &block : ResultSet -> U) : Array(U) forall U","location":{"filename":"src/db/query_methods.cr","line_number":212,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L212"},"def":{"name":"query_all","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":1,"yields":1,"block_arity":1,"block_arg":{"name":"block","external_name":"block","restriction":"(ResultSet -> U)"},"return_type":"Array(U)","visibility":"Public","body":"ary = [] of U\nquery_each(query, *args_, args: args) do |rs|\n ary.push(yield rs)\nend\nary\n"}},{"html_id":"query_all(query,*args_,args:Array|Nil=nil,astypes:Tuple)-instance-method","name":"query_all","doc":"Executes a *query* and returns an array where each row is\nread as a tuple of the given *types*.\n\n```\ncontacts = db.query_all \"select name, age from contacts\", as: {String, Int32}\n```","summary":"

Executes a query and returns an array where each row is read as a tuple of the given types.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"Tuple"}],"args_string":"(query, *args_, args : Array | Nil = nil, as types : Tuple)","args_html":"(query, *args_, args : Array | Nil = nil, as types : Tuple)","location":{"filename":"src/db/query_methods.cr","line_number":226,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L226"},"def":{"name":"query_all","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"Tuple"}],"splat_index":1,"visibility":"Public","body":"query_all(query, *args_, args: args) do |rs|\n rs.read(*types)\nend"}},{"html_id":"query_all(query,*args_,args:Array|Nil=nil,astypes:NamedTuple)-instance-method","name":"query_all","doc":"Executes a *query* and returns an array where each row is\nread as a named tuple of the given *types* (the keys of the named tuple\nare not necessarily the column names).\n\n```\ncontacts = db.query_all \"select name, age from contacts\", as: {name: String, age: Int32}\n```","summary":"

Executes a query and returns an array where each row is read as a named tuple of the given types (the keys of the named tuple are not necessarily the column names).

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"NamedTuple"}],"args_string":"(query, *args_, args : Array | Nil = nil, as types : NamedTuple)","args_html":"(query, *args_, args : Array | Nil = nil, as types : NamedTuple)","location":{"filename":"src/db/query_methods.cr","line_number":239,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L239"},"def":{"name":"query_all","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"NamedTuple"}],"splat_index":1,"visibility":"Public","body":"query_all(query, *args_, args: args) do |rs|\n rs.read(**types)\nend"}},{"html_id":"query_all(query,*args_,args:Array|Nil=nil,astype:Class)-instance-method","name":"query_all","doc":"Executes a *query* and returns an array where the\nvalue of each row is read as the given *type*.\n\n```\nnames = db.query_all \"select name from contacts\", as: String\n```","summary":"

Executes a query and returns an array where the value of each row is read as the given type.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"type","external_name":"as","restriction":"Class"}],"args_string":"(query, *args_, args : Array | Nil = nil, as type : Class)","args_html":"(query, *args_, args : Array | Nil = nil, as type : Class)","location":{"filename":"src/db/query_methods.cr","line_number":251,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L251"},"def":{"name":"query_all","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"type","external_name":"as","restriction":"Class"}],"splat_index":1,"visibility":"Public","body":"query_all(query, *args_, args: args) do |rs|\n rs.read(type)\nend"}},{"html_id":"query_each(query,*args_,args:Array|Nil=nil,&)-instance-method","name":"query_each","doc":"Executes a *query* and yields the `ResultSet` once per each row.\nThe `ResultSet` is closed automatically.\n\n```\ndb.query_each \"select name from contacts\" do |rs|\n puts rs.read(String)\nend\n```","summary":"

Executes a query and yields the ResultSet once per each row.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(query, *args_, args : Array | Nil = nil, &)","args_html":"(query, *args_, args : Array | Nil = nil, &)","location":{"filename":"src/db/query_methods.cr","line_number":265,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L265"},"def":{"name":"query_each","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":1,"yields":1,"block_arity":1,"visibility":"Public","body":"query(query, *args_, args: args) do |rs|\n rs.each do\n yield rs\n end\nend"}},{"html_id":"query_one(query,*args_,args:Array|Nil=nil,&block:ResultSet->U):UforallU-instance-method","name":"query_one","doc":"Executes a *query* that expects a single row and yields a `ResultSet`\npositioned at that first row.\n\nThe given block must not invoke `move_next` on the yielded result set.\n\nRaises `DB::NoResultsError` if there were no rows.\nRaises `DB::Error` if there were more than one row.\n\n```\nname = db.query_one \"select name from contacts where id = ?\", 18, &.read(String)\n```","summary":"

Executes a query that expects a single row and yields a ResultSet positioned at that first row.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(query, *args_, args : Array | Nil = nil, &block : ResultSet -> U) : U forall U","args_html":"(query, *args_, args : Array | Nil = nil, &block : ResultSet -> U) : U forall U","location":{"filename":"src/db/query_methods.cr","line_number":76,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L76"},"def":{"name":"query_one","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":1,"yields":1,"block_arity":1,"block_arg":{"name":"block","external_name":"block","restriction":"(ResultSet -> U)"},"return_type":"U","visibility":"Public","body":"query(query, *args_, args: args) do |rs|\n if rs.move_next\n else\n raise(DB::NoResultsError.new(\"no results\"))\n end\n value = yield rs\n if rs.move_next\n raise(DB::Error.new(\"more than one row\"))\n end\n return value\nend"}},{"html_id":"query_one(query,*args_,args:Array|Nil=nil,astypes:Tuple)-instance-method","name":"query_one","doc":"Executes a *query* that expects a single row and returns it\nas a tuple of the given *types*.\n\nRaises `DB::NoResultsError` if there were no rows.\nRaises `DB::Error` if there were more than one row.\n\n```\ndb.query_one \"select name, age from contacts where id = ?\", 1, as: {String, Int32}\n```","summary":"

Executes a query that expects a single row and returns it as a tuple of the given types.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"Tuple"}],"args_string":"(query, *args_, args : Array | Nil = nil, as types : Tuple)","args_html":"(query, *args_, args : Array | Nil = nil, as types : Tuple)","location":{"filename":"src/db/query_methods.cr","line_number":95,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L95"},"def":{"name":"query_one","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"Tuple"}],"splat_index":1,"visibility":"Public","body":"query_one(query, *args_, args: args) do |rs|\n rs.read(*types)\nend"}},{"html_id":"query_one(query,*args_,args:Array|Nil=nil,astypes:NamedTuple)-instance-method","name":"query_one","doc":"Executes a *query* that expects a single row and returns it\nas a named tuple of the given *types* (the keys of the named tuple\nare not necessarily the column names).\n\nRaises `DB::NoResultsError` if there were no rows.\nRaises `DB::Error` if there were more than one row.\n\n```\ndb.query_one \"select name, age from contacts where id = ?\", 1, as: {name: String, age: Int32}\n```","summary":"

Executes a query that expects a single row and returns it as a named tuple of the given types (the keys of the named tuple are not necessarily the column names).

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"NamedTuple"}],"args_string":"(query, *args_, args : Array | Nil = nil, as types : NamedTuple)","args_html":"(query, *args_, args : Array | Nil = nil, as types : NamedTuple)","location":{"filename":"src/db/query_methods.cr","line_number":111,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L111"},"def":{"name":"query_one","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"NamedTuple"}],"splat_index":1,"visibility":"Public","body":"query_one(query, *args_, args: args) do |rs|\n rs.read(**types)\nend"}},{"html_id":"query_one(query,*args_,args:Array|Nil=nil,astype:Class)-instance-method","name":"query_one","doc":"Executes a *query* that expects a single row\nand returns the first column's value as the given *type*.\n\nRaises `DB::NoResultsError` if there were no rows.\nRaises `DB::Error` if there were more than one row.\n\n```\ndb.query_one \"select name from contacts where id = ?\", 1, as: String\n```","summary":"

Executes a query that expects a single row and returns the first column's value as the given type.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"type","external_name":"as","restriction":"Class"}],"args_string":"(query, *args_, args : Array | Nil = nil, as type : Class)","args_html":"(query, *args_, args : Array | Nil = nil, as type : Class)","location":{"filename":"src/db/query_methods.cr","line_number":126,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L126"},"def":{"name":"query_one","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"type","external_name":"as","restriction":"Class"}],"splat_index":1,"visibility":"Public","body":"query_one(query, *args_, args: args) do |rs|\n rs.read(type)\nend"}},{"html_id":"query_one?(query,*args_,args:Array|Nil=nil,&block:ResultSet->U):U|NilforallU-instance-method","name":"query_one?","doc":"Executes a *query* that expects at most a single row and yields a `ResultSet`\npositioned at that first row.\n\nReturns `nil`, not invoking the block, if there were no rows.\n\nRaises `DB::Error` if there were more than one row\n(this ends up invoking the block once).\n\n```\nname = db.query_one? \"select name from contacts where id = ?\", 18, &.read(String)\ntypeof(name) # => String | Nil\n```","summary":"

Executes a query that expects at most a single row and yields a ResultSet positioned at that first row.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(query, *args_, args : Array | Nil = nil, &block : ResultSet -> U) : U | Nil forall U","args_html":"(query, *args_, args : Array | Nil = nil, &block : ResultSet -> U) : U | Nil forall U","location":{"filename":"src/db/query_methods.cr","line_number":144,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L144"},"def":{"name":"query_one?","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":1,"yields":1,"block_arity":1,"block_arg":{"name":"block","external_name":"block","restriction":"(ResultSet -> U)"},"return_type":"U | ::Nil","visibility":"Public","body":"query(query, *args_, args: args) do |rs|\n if rs.move_next\n else\n return nil\n end\n value = yield rs\n if rs.move_next\n raise(DB::Error.new(\"more than one row\"))\n end\n return value\nend"}},{"html_id":"query_one?(query,*args_,args:Array|Nil=nil,astypes:Tuple)-instance-method","name":"query_one?","doc":"Executes a *query* that expects a single row and returns it\nas a tuple of the given *types*.\n\nReturns `nil` if there were no rows.\n\nRaises `DB::Error` if there were more than one row.\n\n```\nresult = db.query_one? \"select name, age from contacts where id = ?\", 1, as: {String, Int32}\ntypeof(result) # => Tuple(String, Int32) | Nil\n```","summary":"

Executes a query that expects a single row and returns it as a tuple of the given types.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"Tuple"}],"args_string":"(query, *args_, args : Array | Nil = nil, as types : Tuple)","args_html":"(query, *args_, args : Array | Nil = nil, as types : Tuple)","location":{"filename":"src/db/query_methods.cr","line_number":165,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L165"},"def":{"name":"query_one?","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"Tuple"}],"splat_index":1,"visibility":"Public","body":"query_one?(query, *args_, args: args) do |rs|\n rs.read(*types)\nend"}},{"html_id":"query_one?(query,*args_,args:Array|Nil=nil,astypes:NamedTuple)-instance-method","name":"query_one?","doc":"Executes a *query* that expects a single row and returns it\nas a named tuple of the given *types* (the keys of the named tuple\nare not necessarily the column names).\n\nReturns `nil` if there were no rows.\n\nRaises `DB::Error` if there were more than one row.\n\n```\nresult = db.query_one? \"select name, age from contacts where id = ?\", 1, as: {age: String, name: Int32}\ntypeof(result) # => NamedTuple(age: String, name: Int32) | Nil\n```","summary":"

Executes a query that expects a single row and returns it as a named tuple of the given types (the keys of the named tuple are not necessarily the column names).

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"NamedTuple"}],"args_string":"(query, *args_, args : Array | Nil = nil, as types : NamedTuple)","args_html":"(query, *args_, args : Array | Nil = nil, as types : NamedTuple)","location":{"filename":"src/db/query_methods.cr","line_number":183,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L183"},"def":{"name":"query_one?","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"types","external_name":"as","restriction":"NamedTuple"}],"splat_index":1,"visibility":"Public","body":"query_one?(query, *args_, args: args) do |rs|\n rs.read(**types)\nend"}},{"html_id":"query_one?(query,*args_,args:Array|Nil=nil,astype:Class)-instance-method","name":"query_one?","doc":"Executes a *query* that expects a single row\nand returns the first column's value as the given *type*.\n\nReturns `nil` if there were no rows.\n\nRaises `DB::Error` if there were more than one row.\n\n```\nname = db.query_one? \"select name from contacts where id = ?\", 1, as: String\ntypeof(name) # => String?\n```","summary":"

Executes a query that expects a single row and returns the first column's value as the given type.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"type","external_name":"as","restriction":"Class"}],"args_string":"(query, *args_, args : Array | Nil = nil, as type : Class)","args_html":"(query, *args_, args : Array | Nil = nil, as type : Class)","location":{"filename":"src/db/query_methods.cr","line_number":200,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L200"},"def":{"name":"query_one?","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"},{"name":"type","external_name":"as","restriction":"Class"}],"splat_index":1,"visibility":"Public","body":"query_one?(query, *args_, args: args) do |rs|\n rs.read(type)\nend"}},{"html_id":"scalar(query,*args_,args:Array|Nil=nil)-instance-method","name":"scalar","doc":"Performs the `query` and returns a single scalar value\n\n```\nputs db.scalar(\"SELECT MAX(name)\").as(String) # => (a String)\n```","summary":"

Performs the #query and returns a single scalar value

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(query, *args_, args : Array | Nil = nil)","args_html":"(query, *args_, args : Array | Nil = nil)","location":{"filename":"src/db/query_methods.cr","line_number":283,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/query_methods.cr#L283"},"def":{"name":"scalar","args":[{"name":"query","external_name":"query","restriction":""},{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":1,"visibility":"Public","body":"(build(query)).scalar(*args_, args: args)"}}]},{"html_id":"db/DB/ResultSet","path":"DB/ResultSet.html","kind":"class","full_name":"DB::ResultSet","name":"ResultSet","abstract":true,"superclass":{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"db/DB/Disposable","kind":"module","full_name":"DB::Disposable","name":"Disposable"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/result_set.cr","line_number":22,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L22"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/DB/Disposable","kind":"module","full_name":"DB::Disposable","name":"Disposable"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"The response of a query performed on a `Database`.\n\nSee `DB` for a complete sample.\n\nEach `#read` call consumes the result and moves to the next column.\nEach column must be read in order.\nAt any moment a `#move_next` can be invoked, meaning to skip the\nremaining, or even all the columns, in the current row.\nAlso it is not mandatory to consume the whole `ResultSet`, hence an iteration\nthrough `#each` or `#move_next` can be stopped.\n\n**Note:** depending on how the `ResultSet` was obtained it might be mandatory an\nexplicit call to `#close`. Check `QueryMethods#query`.\n\n### Note to implementors\n\n1. Override `#move_next` to move to the next row.\n2. Override `#read` returning the next value in the row.\n3. (Optional) Override `#read(t)` for some types `t` for which custom logic other than a simple cast is needed.\n4. Override `#column_count`, `#column_name`.","summary":"

The response of a query performed on a Database.

","constructors":[{"html_id":"new(statement:DB::Statement)-class-method","name":"new","abstract":false,"args":[{"name":"statement","external_name":"statement","restriction":"DB::Statement"}],"args_string":"(statement : DB::Statement)","args_html":"(statement : DB::Statement)","location":{"filename":"src/db/result_set.cr","line_number":28,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L28"},"def":{"name":"new","args":[{"name":"statement","external_name":"statement","restriction":"DB::Statement"}],"visibility":"Public","body":"_ = allocate\n_.initialize(statement)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"column_count:Int32-instance-method","name":"column_count","doc":"Returns the number of columns in the result","summary":"

Returns the number of columns in the result

","abstract":true,"location":{"filename":"src/db/result_set.cr","line_number":59,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L59"},"def":{"name":"column_count","return_type":"Int32","visibility":"Public","body":""}},{"html_id":"column_name(index:Int32):String-instance-method","name":"column_name","doc":"Returns the name of the column in `index` 0-based position.","summary":"

Returns the name of the column in index 0-based position.

","abstract":true,"args":[{"name":"index","external_name":"index","restriction":"Int32"}],"args_string":"(index : Int32) : String","args_html":"(index : Int32) : String","location":{"filename":"src/db/result_set.cr","line_number":62,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L62"},"def":{"name":"column_name","args":[{"name":"index","external_name":"index","restriction":"Int32"}],"return_type":"String","visibility":"Public","body":""}},{"html_id":"column_names-instance-method","name":"column_names","doc":"Returns the name of the columns.","summary":"

Returns the name of the columns.

","abstract":false,"location":{"filename":"src/db/result_set.cr","line_number":65,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L65"},"def":{"name":"column_names","visibility":"Public","body":"Array(String).new(column_count) do |i|\n column_name(i)\nend"}},{"html_id":"each(&)-instance-method","name":"each","doc":"Iterates over all the rows","summary":"

Iterates over all the rows

","abstract":false,"location":{"filename":"src/db/result_set.cr","line_number":38,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L38"},"def":{"name":"each","yields":0,"block_arity":0,"visibility":"Public","body":"while move_next\n yield\nend"}},{"html_id":"each_column(&)-instance-method","name":"each_column","doc":"Iterates over all the columns","summary":"

Iterates over all the columns

","abstract":false,"location":{"filename":"src/db/result_set.cr","line_number":45,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L45"},"def":{"name":"each_column","yields":1,"block_arity":1,"visibility":"Public","body":"column_count.times do |x|\n yield column_name(x)\nend"}},{"html_id":"move_next:Bool-instance-method","name":"move_next","doc":"Move the next row in the result.\nReturn `false` if no more rows are available.\nSee `#each`","summary":"

Move the next row in the result.

","abstract":true,"location":{"filename":"src/db/result_set.cr","line_number":54,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L54"},"def":{"name":"move_next","return_type":"Bool","visibility":"Public","body":""}},{"html_id":"next_column_index:Int32-instance-method","name":"next_column_index","doc":"Returns the column index that corresponds to the next `#read`.\n\nIf the last column of the current row has been read, it must return `#column_count`.","summary":"

Returns the column index that corresponds to the next #read.

","abstract":true,"location":{"filename":"src/db/result_set.cr","line_number":75,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L75"},"def":{"name":"next_column_index","return_type":"Int32","visibility":"Public","body":""}},{"html_id":"read(type:Enum.class)-instance-method","name":"read","doc":"Read the value based on the given `enum` type, supporting both string and\nnumeric column types.\n\n```\nenum Status\n Pending\n Complete\nend\n\ndb.query \"SELECT 'complete'\" do |rs|\n rs.read Status # => Status::Complete\nend\n```","summary":"

Read the value based on the given enum type, supporting both string and numeric column types.

","abstract":false,"args":[{"name":"type","external_name":"type","restriction":"Enum.class"}],"args_string":"(type : Enum.class)","args_html":"(type : Enum.class)","location":{"filename":"src/db/result_set.cr","line_number":112,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L112"},"def":{"name":"read","args":[{"name":"type","external_name":"type","restriction":"Enum.class"}],"visibility":"Public","body":"type.new(self)"}},{"html_id":"read(type:DB::Mappable.class)-instance-method","name":"read","doc":"Reads the next columns and maps them to a class","summary":"

Reads the next columns and maps them to a class

","abstract":false,"args":[{"name":"type","external_name":"type","restriction":"DB::Mappable.class"}],"args_string":"(type : DB::Mappable.class)","args_html":"(type : DB::Mappable.class)","location":{"filename":"src/db/result_set.cr","line_number":78,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L78"},"def":{"name":"read","args":[{"name":"type","external_name":"type","restriction":"DB::Mappable.class"}],"visibility":"Public","body":"type.new(self)"}},{"html_id":"read(type:T.class):TforallT-instance-method","name":"read","doc":"Reads the next column value as a **type**","summary":"

Reads the next column value as a type

","abstract":false,"args":[{"name":"type","external_name":"type","restriction":"T.class"}],"args_string":"(type : T.class) : T forall T","args_html":"(type : T.class) : T forall T","location":{"filename":"src/db/result_set.cr","line_number":83,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L83"},"def":{"name":"read","args":[{"name":"type","external_name":"type","restriction":"T.class"}],"return_type":"T","visibility":"Public","body":"col_index = next_column_index\nvalue = read\nif value.is_a?(T)\n value\nelse\n raise(DB::ColumnTypeMismatchError.new(context: \"#{self.class}#read\", column_index: col_index, column_name: column_name(col_index), column_type: value.class.to_s, expected_type: T.to_s))\nend\n"}},{"html_id":"read-instance-method","name":"read","doc":"Reads the next column value","summary":"

Reads the next column value

","abstract":true,"location":{"filename":"src/db/result_set.cr","line_number":70,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L70"},"def":{"name":"read","visibility":"Public","body":""}},{"html_id":"read(*types:Class)-instance-method","name":"read","doc":"Reads the next columns and returns a tuple of the values.","summary":"

Reads the next columns and returns a tuple of the values.

","abstract":false,"args":[{"name":"types","external_name":"types","restriction":"Class"}],"args_string":"(*types : Class)","args_html":"(*types : Class)","location":{"filename":"src/db/result_set.cr","line_number":117,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L117"},"def":{"name":"read","args":[{"name":"types","external_name":"types","restriction":"Class"}],"splat_index":0,"visibility":"Public","body":"internal_read(*types)"}},{"html_id":"read(**types:Class)-instance-method","name":"read","doc":"Reads the next columns and returns a named tuple of the values.","summary":"

Reads the next columns and returns a named tuple of the values.

","abstract":false,"location":{"filename":"src/db/result_set.cr","line_number":122,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L122"},"def":{"name":"read","double_splat":{"name":"types","external_name":"types","restriction":"Class"},"visibility":"Public","body":"internal_read(**types)"}}]},{"html_id":"db/DB/Rollback","path":"DB/Rollback.html","kind":"class","full_name":"DB::Rollback","name":"Rollback","abstract":false,"superclass":{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},"ancestors":[{"html_id":"db/DB/Error","kind":"class","full_name":"DB::Error","name":"Error"},{"html_id":"db/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/error.cr","line_number":57,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/error.cr#L57"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"}},{"html_id":"db/DB/SavePointTransaction","path":"DB/SavePointTransaction.html","kind":"class","full_name":"DB::SavePointTransaction","name":"SavePointTransaction","abstract":false,"superclass":{"html_id":"db/DB/Transaction","kind":"class","full_name":"DB::Transaction","name":"Transaction"},"ancestors":[{"html_id":"db/DB/Transaction","kind":"class","full_name":"DB::Transaction","name":"Transaction"},{"html_id":"db/DB/BeginTransaction","kind":"module","full_name":"DB::BeginTransaction","name":"BeginTransaction"},{"html_id":"db/DB/Disposable","kind":"module","full_name":"DB::Disposable","name":"Disposable"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/transaction.cr","line_number":94,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L94"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"constructors":[{"html_id":"new(parent:Transaction,savepoint_name:String)-class-method","name":"new","abstract":false,"args":[{"name":"parent","external_name":"parent","restriction":"Transaction"},{"name":"savepoint_name","external_name":"savepoint_name","restriction":"String"}],"args_string":"(parent : Transaction, savepoint_name : String)","args_html":"(parent : Transaction, savepoint_name : String)","location":{"filename":"src/db/transaction.cr","line_number":97,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L97"},"def":{"name":"new","args":[{"name":"parent","external_name":"parent","restriction":"Transaction"},{"name":"savepoint_name","external_name":"savepoint_name","restriction":"String"}],"visibility":"Public","body":"_ = allocate\n_.initialize(parent, savepoint_name)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"begin_transaction:Transaction-instance-method","name":"begin_transaction","doc":"Creates a transaction from the current context.\nIf is expected that either `Transaction#commit` or `Transaction#rollback`\nare called explicitly to release the context.","summary":"

Creates a transaction from the current context.

","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":117,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L117"},"def":{"name":"begin_transaction","return_type":"Transaction","visibility":"Public","body":"if @nested_transaction\n raise(DB::Error.new(\"There is an existing nested transaction in this transaction\"))\nend\n@nested_transaction = true\ncreate_save_point_transaction(self)\n"}},{"html_id":"commit-instance-method","name":"commit","doc":"commits the current transaction","summary":"

commits the current transaction

","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":103,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L103"},"def":{"name":"commit","visibility":"Public","body":"@connection.perform_release_savepoint(@savepoint_name)\nsuper()\n"}},{"html_id":"connection:Connection-instance-method","name":"connection","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":95,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L95"},"def":{"name":"connection","return_type":"Connection","visibility":"Public","body":"@connection"}},{"html_id":"create_save_point_transaction(parent:Transaction)-instance-method","name":"create_save_point_transaction","abstract":false,"args":[{"name":"parent","external_name":"parent","restriction":"Transaction"}],"args_string":"(parent : Transaction)","args_html":"(parent : Transaction)","location":{"filename":"src/db/transaction.cr","line_number":123,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L123"},"def":{"name":"create_save_point_transaction","args":[{"name":"parent","external_name":"parent","restriction":"Transaction"}],"visibility":"Public","body":"@parent.create_save_point_transaction(parent)"}},{"html_id":"release_from_nested_transaction-instance-method","name":"release_from_nested_transaction","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":127,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L127"},"def":{"name":"release_from_nested_transaction","visibility":"Public","body":"@nested_transaction = false"}},{"html_id":"rollback-instance-method","name":"rollback","doc":"rollbacks the current transaction","summary":"

rollbacks the current transaction

","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":108,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L108"},"def":{"name":"rollback","visibility":"Public","body":"@connection.perform_rollback_savepoint(@savepoint_name)\nsuper()\n"}}]},{"html_id":"db/DB/Serializable","path":"DB/Serializable.html","kind":"module","full_name":"DB::Serializable","name":"Serializable","abstract":false,"locations":[{"filename":"src/db/serializable.cr","line_number":67,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/serializable.cr#L67"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"The `DB::Serialization` module automatically generates methods for DB serialization when included.\n\nOnce included, `ResultSet#read(t)` populates properties of the class from the\n`ResultSet`.\n\n### Example\n\n```\nrequire \"db\"\n\nclass Employee\n include DB::Serializable\n\n property title : String\n property name : String\nend\n\nemployees = Employee.from_rs(db.query(\"SELECT title, name FROM employees\"))\nemployees[0].title # => \"Manager\"\nemployees[0].name # => \"John\"\n```\n\n### Usage\n\n`DB::Serializable` was designed in analogue with `JSON::Serializable`, so usage is identical.\n However, like `DB.mapping`, `DB::Serializable` is **strict by default**, so extra columns will raise `DB::MappingException`s.\n\nSimilar to `JSON::Field`, there is an annotation `DB::Field` that can be used to set serialization behavior\non individual instance variables.\n\n```\nclass Employee\n include DB::Serializable\n\n property title : String\n\n @[DB::Field(key: \"firstname\")]\n property name : String?\nend\n```\n\n`DB::Field` properties:\n* **ignore**: if `true`, skip this field in serialization and deserialization (`false` by default)\n* **key**: defines which column to read from a `ResultSet` (name of the instance variable by default)\n* **converter**: defines an alternate type for parsing results. The given type must define `#from_rs(DB::ResultSet)` and return an instance of the included type.\n\n### `DB::Serializable::NonStrict`\n\nIncluding this module is functionally identical to passing `{strict: false}` to `DB.mapping`: extra columns will not raise.\n\n```\nclass Employee\n include DB::Serializable\n include DB::Serializable::NonStrict\n\n property title : String\n property name : String\nend\n\n# does not raise!\nemployees = Employee.from_rs(db.query(\"SELECT title, name, age FROM employees\"))\n```","summary":"

The DB::Serialization module automatically generates methods for DB serialization when included.

","constructors":[{"html_id":"new(*,__set_for_db_serializablers:DB::ResultSet)-class-method","name":"new","abstract":false,"args":[{"name":"","external_name":"","restriction":""},{"name":"rs","external_name":"__set_for_db_serializable","restriction":"::DB::ResultSet"}],"args_string":"(*, __set_for_db_serializable rs : DB::ResultSet)","args_html":"(*, __set_for_db_serializable rs : DB::ResultSet)","location":{"filename":"src/db/serializable.cr","line_number":104,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/serializable.cr#L104"},"def":{"name":"new","args":[{"name":"","external_name":"","restriction":""},{"name":"rs","external_name":"__set_for_db_serializable","restriction":"::DB::ResultSet"}],"splat_index":0,"visibility":"Public","body":"_ = allocate\n_.initialize(__set_for_db_serializable: rs)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"types":[{"html_id":"db/DB/Serializable/NonStrict","path":"DB/Serializable/NonStrict.html","kind":"module","full_name":"DB::Serializable::NonStrict","name":"NonStrict","abstract":false,"locations":[{"filename":"src/db/serializable.cr","line_number":179,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/serializable.cr#L179"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB/Serializable","kind":"module","full_name":"DB::Serializable","name":"Serializable"}}]},{"html_id":"db/DB/SessionMethods","path":"DB/SessionMethods.html","kind":"module","full_name":"DB::SessionMethods(Session, Stmt)","name":"SessionMethods","abstract":false,"ancestors":[{"html_id":"db/DB/QueryMethods","kind":"module","full_name":"DB::QueryMethods","name":"QueryMethods"}],"locations":[{"filename":"src/db/session_methods.cr","line_number":10,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L10"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/DB/QueryMethods","kind":"module","full_name":"DB::QueryMethods","name":"QueryMethods"}],"including_types":[{"html_id":"db/DB/Connection","kind":"class","full_name":"DB::Connection","name":"Connection"},{"html_id":"db/DB/Database","kind":"class","full_name":"DB::Database","name":"Database"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Methods that are shared accross session like objects:\n - Database\n - Connection\n\nClasses that includes this module are able to execute\nqueries and statements in both prepared and unprepared fashion.\n\nThis module serves for dsl reuse over session like objects.","summary":"

Methods that are shared accross session like objects: - Database - Connection

","instance_methods":[{"html_id":"build(query):Stmt-instance-method","name":"build","doc":":nodoc:","summary":"

:nodoc:

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""}],"args_string":"(query) : Stmt","args_html":"(query) : Stmt","location":{"filename":"src/db/session_methods.cr","line_number":23,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L23"},"def":{"name":"build","args":[{"name":"query","external_name":"query","restriction":""}],"return_type":"Stmt","visibility":"Public","body":"if prepared_statements?\n stmt = fetch_or_build_prepared_statement(query)\n if !prepared_statements_cache?\n if stmt.responds_to?(:\"auto_close=\")\n stmt.auto_close = true\n end\n end\n stmt\nelse\n build_unprepared_statement(query)\nend"}},{"html_id":"build_unprepared_statement(query):Stmt-instance-method","name":"build_unprepared_statement","abstract":true,"args":[{"name":"query","external_name":"query","restriction":""}],"args_string":"(query) : Stmt","args_html":"(query) : Stmt","location":{"filename":"src/db/session_methods.cr","line_number":21,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L21"},"def":{"name":"build_unprepared_statement","args":[{"name":"query","external_name":"query","restriction":""}],"return_type":"Stmt","visibility":"Public","body":""}},{"html_id":"fetch_or_build_prepared_statement(query):Stmt-instance-method","name":"fetch_or_build_prepared_statement","abstract":true,"args":[{"name":"query","external_name":"query","restriction":""}],"args_string":"(query) : Stmt","args_html":"(query) : Stmt","location":{"filename":"src/db/session_methods.cr","line_number":19,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L19"},"def":{"name":"fetch_or_build_prepared_statement","args":[{"name":"query","external_name":"query","restriction":""}],"return_type":"Stmt","visibility":"Public","body":""}},{"html_id":"prepared(query)-instance-method","name":"prepared","doc":"Returns a prepared `Statement` that has not been executed yet.","summary":"

Returns a prepared Statement that has not been executed yet.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""}],"args_string":"(query)","args_html":"(query)","location":{"filename":"src/db/session_methods.cr","line_number":50,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L50"},"def":{"name":"prepared","args":[{"name":"query","external_name":"query","restriction":""}],"visibility":"Public","body":"prepared.build(query)"}},{"html_id":"prepared-instance-method","name":"prepared","doc":"dsl helper to build prepared statements\nreturns a value that includes `QueryMethods`","summary":"

dsl helper to build prepared statements returns a value that includes QueryMethods

","abstract":false,"location":{"filename":"src/db/session_methods.cr","line_number":45,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L45"},"def":{"name":"prepared","visibility":"Public","body":"PreparedQuery(Session, Stmt).new(self)"}},{"html_id":"prepared_statements?:Bool-instance-method","name":"prepared_statements?","doc":"Returns whether by default the statements should\nbe prepared or not.","summary":"

Returns whether by default the statements should be prepared or not.

","abstract":true,"location":{"filename":"src/db/session_methods.cr","line_number":15,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L15"},"def":{"name":"prepared_statements?","return_type":"Bool","visibility":"Public","body":""}},{"html_id":"prepared_statements_cache?:Bool-instance-method","name":"prepared_statements_cache?","abstract":true,"location":{"filename":"src/db/session_methods.cr","line_number":17,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L17"},"def":{"name":"prepared_statements_cache?","return_type":"Bool","visibility":"Public","body":""}},{"html_id":"unprepared(query)-instance-method","name":"unprepared","doc":"Returns an unprepared `Statement` that has not been executed yet.","summary":"

Returns an unprepared Statement that has not been executed yet.

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""}],"args_string":"(query)","args_html":"(query)","location":{"filename":"src/db/session_methods.cr","line_number":61,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L61"},"def":{"name":"unprepared","args":[{"name":"query","external_name":"query","restriction":""}],"visibility":"Public","body":"unprepared.build(query)"}},{"html_id":"unprepared-instance-method","name":"unprepared","doc":"dsl helper to build unprepared statements\nreturns a value that includes `QueryMethods`","summary":"

dsl helper to build unprepared statements returns a value that includes QueryMethods

","abstract":false,"location":{"filename":"src/db/session_methods.cr","line_number":56,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L56"},"def":{"name":"unprepared","visibility":"Public","body":"UnpreparedQuery(Session, Stmt).new(self)"}}],"types":[{"html_id":"db/DB/SessionMethods/PreparedQuery","path":"DB/SessionMethods/PreparedQuery.html","kind":"struct","full_name":"DB::SessionMethods::PreparedQuery(Session, Stmt)","name":"PreparedQuery","abstract":false,"superclass":{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"db/DB/QueryMethods","kind":"module","full_name":"DB::QueryMethods","name":"QueryMethods"},{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/session_methods.cr","line_number":65,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L65"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/DB/QueryMethods","kind":"module","full_name":"DB::QueryMethods","name":"QueryMethods"}],"namespace":{"html_id":"db/DB/SessionMethods","kind":"module","full_name":"DB::SessionMethods(Session, Stmt)","name":"SessionMethods"},"constructors":[{"html_id":"new(session:Session)-class-method","name":"new","abstract":false,"args":[{"name":"session","external_name":"session","restriction":"Session"}],"args_string":"(session : Session)","args_html":"(session : Session)","location":{"filename":"src/db/session_methods.cr","line_number":68,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L68"},"def":{"name":"new","args":[{"name":"session","external_name":"session","restriction":"Session"}],"visibility":"Public","body":"_ = PreparedQuery(Session, Stmt).allocate\n_.initialize(session)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"build(query):Stmt-instance-method","name":"build","doc":":nodoc:","summary":"

:nodoc:

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""}],"args_string":"(query) : Stmt","args_html":"(query) : Stmt","location":{"filename":"src/db/session_methods.cr","line_number":71,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L71"},"def":{"name":"build","args":[{"name":"query","external_name":"query","restriction":""}],"return_type":"Stmt","visibility":"Public","body":"@session.fetch_or_build_prepared_statement(query)"}}]},{"html_id":"db/DB/SessionMethods/UnpreparedQuery","path":"DB/SessionMethods/UnpreparedQuery.html","kind":"struct","full_name":"DB::SessionMethods::UnpreparedQuery(Session, Stmt)","name":"UnpreparedQuery","abstract":false,"superclass":{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"db/DB/QueryMethods","kind":"module","full_name":"DB::QueryMethods","name":"QueryMethods"},{"html_id":"db/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/session_methods.cr","line_number":76,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L76"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/DB/QueryMethods","kind":"module","full_name":"DB::QueryMethods","name":"QueryMethods"}],"namespace":{"html_id":"db/DB/SessionMethods","kind":"module","full_name":"DB::SessionMethods(Session, Stmt)","name":"SessionMethods"},"constructors":[{"html_id":"new(session:Session)-class-method","name":"new","abstract":false,"args":[{"name":"session","external_name":"session","restriction":"Session"}],"args_string":"(session : Session)","args_html":"(session : Session)","location":{"filename":"src/db/session_methods.cr","line_number":79,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L79"},"def":{"name":"new","args":[{"name":"session","external_name":"session","restriction":"Session"}],"visibility":"Public","body":"_ = UnpreparedQuery(Session, Stmt).allocate\n_.initialize(session)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"build(query):Stmt-instance-method","name":"build","doc":":nodoc:","summary":"

:nodoc:

","abstract":false,"args":[{"name":"query","external_name":"query","restriction":""}],"args_string":"(query) : Stmt","args_html":"(query) : Stmt","location":{"filename":"src/db/session_methods.cr","line_number":82,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/session_methods.cr#L82"},"def":{"name":"build","args":[{"name":"query","external_name":"query","restriction":""}],"return_type":"Stmt","visibility":"Public","body":"@session.build_unprepared_statement(query)"}}]}]},{"html_id":"db/DB/Statement","path":"DB/Statement.html","kind":"class","full_name":"DB::Statement","name":"Statement","abstract":true,"superclass":{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"db/DB/Disposable","kind":"module","full_name":"DB::Disposable","name":"Disposable"},{"html_id":"db/DB/StatementMethods","kind":"module","full_name":"DB::StatementMethods","name":"StatementMethods"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/statement.cr","line_number":43,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L43"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/DB/Disposable","kind":"module","full_name":"DB::Disposable","name":"Disposable"},{"html_id":"db/DB/StatementMethods","kind":"module","full_name":"DB::StatementMethods","name":"StatementMethods"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Represents a query in a `Connection`.\nIt should be created by `QueryMethods`.\n\n### Note to implementors\n\n1. Subclass `Statements`\n2. `Statements` are created from a custom driver `Connection#prepare` method.\n3. `#perform_query` executes a query that is expected to return a `ResultSet`\n4. `#perform_exec` executes a query that is expected to return an `ExecResult`\n6. `#do_close` is called to release the statement resources.","summary":"

Represents a query in a Connection.

","constructors":[{"html_id":"new(connection:Connection,command:String)-class-method","name":"new","abstract":false,"args":[{"name":"connection","external_name":"connection","restriction":"Connection"},{"name":"command","external_name":"command","restriction":"String"}],"args_string":"(connection : Connection, command : String)","args_html":"(connection : Connection, command : String)","location":{"filename":"src/db/statement.cr","line_number":55,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L55"},"def":{"name":"new","args":[{"name":"connection","external_name":"connection","restriction":"Connection"},{"name":"command","external_name":"command","restriction":"String"}],"visibility":"Public","body":"_ = allocate\n_.initialize(connection, command)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"command:String-instance-method","name":"command","abstract":false,"location":{"filename":"src/db/statement.cr","line_number":53,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L53"},"def":{"name":"command","return_type":"String","visibility":"Public","body":"@command"}},{"html_id":"exec:DB::ExecResult-instance-method","name":"exec","doc":"See `QueryMethods#exec`","summary":"

See QueryMethods#exec

","abstract":false,"location":{"filename":"src/db/statement.cr","line_number":72,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L72"},"def":{"name":"exec","return_type":"DB::ExecResult","visibility":"Public","body":"perform_exec_and_release(Slice(Any).empty)"}},{"html_id":"exec(*args_,args:Array|Nil=nil):DB::ExecResult-instance-method","name":"exec","doc":"See `QueryMethods#exec`","summary":"

See QueryMethods#exec

","abstract":false,"args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(*args_, args : Array | Nil = nil) : DB::ExecResult","args_html":"(*args_, args : Array | Nil = nil) : DB::ExecResult","location":{"filename":"src/db/statement.cr","line_number":77,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L77"},"def":{"name":"exec","args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":0,"return_type":"DB::ExecResult","visibility":"Public","body":"perform_exec_and_release(EnumerableConcat.build(args_, args))"}},{"html_id":"query:DB::ResultSet-instance-method","name":"query","doc":"See `QueryMethods#query`","summary":"

See QueryMethods#query

","abstract":false,"location":{"filename":"src/db/statement.cr","line_number":82,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L82"},"def":{"name":"query","return_type":"DB::ResultSet","visibility":"Public","body":"perform_query_with_rescue(Tuple.new)"}},{"html_id":"query(*args_,args:Array|Nil=nil):DB::ResultSet-instance-method","name":"query","doc":"See `QueryMethods#query`","summary":"

See QueryMethods#query

","abstract":false,"args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(*args_, args : Array | Nil = nil) : DB::ResultSet","args_html":"(*args_, args : Array | Nil = nil) : DB::ResultSet","location":{"filename":"src/db/statement.cr","line_number":87,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L87"},"def":{"name":"query","args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":0,"return_type":"DB::ResultSet","visibility":"Public","body":"perform_query_with_rescue(EnumerableConcat.build(args_, args))"}},{"html_id":"release_connection-instance-method","name":"release_connection","abstract":false,"location":{"filename":"src/db/statement.cr","line_number":67,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L67"},"def":{"name":"release_connection","visibility":"Public","body":"@connection.release_from_statement"}}],"macros":[{"html_id":"def_around_query_or_exec(&block)-macro","name":"def_around_query_or_exec","doc":"This macro allows injecting code to be run before and after the execution\nof the request. It should return the yielded value. It must be called with 1\nblock argument that will be used to pass the `args : Enumerable`.\n\n```\nclass DB::Statement\n def_around_query_or_exec do |args|\n # do something before query or exec\n res = yield\n # do something after query or exec\n res\n end\nend\n```","summary":"

This macro allows injecting code to be run before and after the execution of the request.

","abstract":false,"location":{"filename":"src/db/statement.cr","line_number":134,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L134"},"def":{"name":"def_around_query_or_exec","block_arg":{"name":"block","external_name":"block","restriction":""},"visibility":"Public","body":" protected def around_query_or_exec(\n%args\n : Enumerable)\n previous_def do\n \n{% if block.args.size != 1 %}\n {% raise(\"Wrong number of block arguments (given #{block.args.size}, expected: 1)\") %}\n {% end %}\n\n\n \n{{ block.args.first.id }}\n = \n%args\n\n \n{{ block.body }}\n\n \nend\n \nend\n \n"}}]},{"html_id":"db/DB/StatementMethods","path":"DB/StatementMethods.html","kind":"module","full_name":"DB::StatementMethods","name":"StatementMethods","abstract":false,"locations":[{"filename":"src/db/statement.cr","line_number":4,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L4"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"including_types":[{"html_id":"db/DB/PoolStatement","kind":"struct","full_name":"DB::PoolStatement","name":"PoolStatement"},{"html_id":"db/DB/Statement","kind":"class","full_name":"DB::Statement","name":"Statement"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Common interface for connection based statements\nand for connection pool statements.","summary":"

Common interface for connection based statements and for connection pool statements.

","instance_methods":[{"html_id":"exec:ExecResult-instance-method","name":"exec","doc":"See `QueryMethods#exec`","summary":"

See QueryMethods#exec

","abstract":true,"location":{"filename":"src/db/statement.cr","line_number":23,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L23"},"def":{"name":"exec","return_type":"ExecResult","visibility":"Public","body":""}},{"html_id":"exec(*args_,args:Array|Nil=nil):ExecResult-instance-method","name":"exec","doc":"See `QueryMethods#exec`","summary":"

See QueryMethods#exec

","abstract":true,"args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(*args_, args : Array | Nil = nil) : ExecResult","args_html":"(*args_, args : Array | Nil = nil) : ExecResult","location":{"filename":"src/db/statement.cr","line_number":25,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L25"},"def":{"name":"exec","args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":0,"return_type":"ExecResult","visibility":"Public","body":""}},{"html_id":"query(*args_,args:Array|Nil=nil,&)-instance-method","name":"query","doc":"See `QueryMethods#query`","summary":"

See QueryMethods#query

","abstract":false,"args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(*args_, args : Array | Nil = nil, &)","args_html":"(*args_, args : Array | Nil = nil, &)","location":{"filename":"src/db/statement.cr","line_number":17,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L17"},"def":{"name":"query","args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":0,"yields":1,"block_arity":1,"visibility":"Public","body":"rs = query(*args_, args: args)\nbegin\n yield rs\nensure\n rs.close\nend\n"}},{"html_id":"query:ResultSet-instance-method","name":"query","doc":"See `QueryMethods#query`","summary":"

See QueryMethods#query

","abstract":true,"location":{"filename":"src/db/statement.cr","line_number":28,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L28"},"def":{"name":"query","return_type":"ResultSet","visibility":"Public","body":""}},{"html_id":"query(*args_,args:Array|Nil=nil):ResultSet-instance-method","name":"query","doc":"See `QueryMethods#query`","summary":"

See QueryMethods#query

","abstract":true,"args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(*args_, args : Array | Nil = nil) : ResultSet","args_html":"(*args_, args : Array | Nil = nil) : ResultSet","location":{"filename":"src/db/statement.cr","line_number":30,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L30"},"def":{"name":"query","args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":0,"return_type":"ResultSet","visibility":"Public","body":""}},{"html_id":"scalar(*args_,args:Array|Nil=nil)-instance-method","name":"scalar","doc":"See `QueryMethods#scalar`","summary":"

See QueryMethods#scalar

","abstract":false,"args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"args_string":"(*args_, args : Array | Nil = nil)","args_html":"(*args_, args : Array | Nil = nil)","location":{"filename":"src/db/statement.cr","line_number":6,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/statement.cr#L6"},"def":{"name":"scalar","args":[{"name":"args_","external_name":"args_","restriction":""},{"name":"args","default_value":"nil","external_name":"args","restriction":"Array | ::Nil"}],"splat_index":0,"visibility":"Public","body":"query(*args_, args: args) do |rs|\n rs.each do\n return rs.read\n end\nend\nraise(NoResultsError.new(\"no results\"))\n"}}]},{"html_id":"db/DB/StringKeyCache","path":"DB/StringKeyCache.html","kind":"class","full_name":"DB::StringKeyCache(T)","name":"StringKeyCache","abstract":false,"superclass":{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/string_key_cache.cr","line_number":2,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/string_key_cache.cr#L2"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"instance_methods":[{"html_id":"clear-instance-method","name":"clear","abstract":false,"location":{"filename":"src/db/string_key_cache.cr","line_number":17,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/string_key_cache.cr#L17"},"def":{"name":"clear","visibility":"Public","body":"@cache.clear"}},{"html_id":"each_value(&)-instance-method","name":"each_value","abstract":false,"location":{"filename":"src/db/string_key_cache.cr","line_number":11,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/string_key_cache.cr#L11"},"def":{"name":"each_value","yields":1,"block_arity":1,"visibility":"Public","body":"@cache.each do |_, value|\n yield value\nend"}},{"html_id":"fetch(key:String,&):T-instance-method","name":"fetch","abstract":false,"args":[{"name":"key","external_name":"key","restriction":"String"}],"args_string":"(key : String, &) : T","args_html":"(key : String, &) : T","location":{"filename":"src/db/string_key_cache.cr","line_number":5,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/string_key_cache.cr#L5"},"def":{"name":"fetch","args":[{"name":"key","external_name":"key","restriction":"String"}],"yields":0,"block_arity":0,"return_type":"T","visibility":"Public","body":"value = @cache.fetch(key, nil)\nif value\nelse\n value = @cache[key] = yield\nend\nvalue\n"}}]},{"html_id":"db/DB/TopLevelTransaction","path":"DB/TopLevelTransaction.html","kind":"class","full_name":"DB::TopLevelTransaction","name":"TopLevelTransaction","abstract":false,"superclass":{"html_id":"db/DB/Transaction","kind":"class","full_name":"DB::Transaction","name":"Transaction"},"ancestors":[{"html_id":"db/DB/Transaction","kind":"class","full_name":"DB::Transaction","name":"Transaction"},{"html_id":"db/DB/BeginTransaction","kind":"module","full_name":"DB::BeginTransaction","name":"BeginTransaction"},{"html_id":"db/DB/Disposable","kind":"module","full_name":"DB::Disposable","name":"Disposable"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/transaction.cr","line_number":38,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L38"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"constructors":[{"html_id":"new(connection:Connection)-class-method","name":"new","abstract":false,"args":[{"name":"connection","external_name":"connection","restriction":"Connection"}],"args_string":"(connection : Connection)","args_html":"(connection : Connection)","location":{"filename":"src/db/transaction.cr","line_number":43,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L43"},"def":{"name":"new","args":[{"name":"connection","external_name":"connection","restriction":"Connection"}],"visibility":"Public","body":"_ = allocate\n_.initialize(connection)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"begin_transaction:Transaction-instance-method","name":"begin_transaction","doc":"Creates a transaction from the current context.\nIf is expected that either `Transaction#commit` or `Transaction#rollback`\nare called explicitly to release the context.","summary":"

Creates a transaction from the current context.

","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":62,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L62"},"def":{"name":"begin_transaction","return_type":"Transaction","visibility":"Public","body":"if @nested_transaction\n raise(DB::Error.new(\"There is an existing nested transaction in this transaction\"))\nend\n@nested_transaction = true\ncreate_save_point_transaction(self)\n"}},{"html_id":"commit-instance-method","name":"commit","doc":"commits the current transaction","summary":"

commits the current transaction

","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":48,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L48"},"def":{"name":"commit","visibility":"Public","body":"@connection.perform_commit_transaction\nsuper()\n"}},{"html_id":"connection:Connection-instance-method","name":"connection","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":39,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L39"},"def":{"name":"connection","return_type":"Connection","visibility":"Public","body":"@connection"}},{"html_id":"rollback-instance-method","name":"rollback","doc":"rollbacks the current transaction","summary":"

rollbacks the current transaction

","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":53,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L53"},"def":{"name":"rollback","visibility":"Public","body":"@connection.perform_rollback_transaction\nsuper()\n"}}]},{"html_id":"db/DB/Transaction","path":"DB/Transaction.html","kind":"class","full_name":"DB::Transaction","name":"Transaction","abstract":true,"superclass":{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"db/DB/BeginTransaction","kind":"module","full_name":"DB::BeginTransaction","name":"BeginTransaction"},{"html_id":"db/DB/Disposable","kind":"module","full_name":"DB::Disposable","name":"Disposable"},{"html_id":"db/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/transaction.cr","line_number":14,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L14"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/DB/BeginTransaction","kind":"module","full_name":"DB::BeginTransaction","name":"BeginTransaction"},{"html_id":"db/DB/Disposable","kind":"module","full_name":"DB::Disposable","name":"Disposable"}],"subclasses":[{"html_id":"db/DB/SavePointTransaction","kind":"class","full_name":"DB::SavePointTransaction","name":"SavePointTransaction"},{"html_id":"db/DB/TopLevelTransaction","kind":"class","full_name":"DB::TopLevelTransaction","name":"TopLevelTransaction"}],"namespace":{"html_id":"db/DB","kind":"module","full_name":"DB","name":"DB"},"doc":"Transactions should be started from `DB#transaction`, `Connection#transaction`\nor `Connection#begin_transaction`.\n\nUse `Transaction#connection` to submit statements to the database.\n\nUse `Transaction#commit` or `Transaction#rollback` to close the ongoing transaction\nexplicitly. Or refer to `BeginTransaction#transaction` for documentation on how to\nuse `#transaction(&block)` methods in `DB` and `Connection`.\n\nNested transactions are supported by using sql `SAVEPOINT`. To start a nested\ntransaction use `Transaction#transaction` or `Transaction#begin_transaction`.\n","summary":"

Transactions should be started from DB#transaction, Connection#transaction or Connection#begin_transaction.

","instance_methods":[{"html_id":"commit-instance-method","name":"commit","doc":"commits the current transaction","summary":"

commits the current transaction

","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":21,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L21"},"def":{"name":"commit","visibility":"Public","body":"close!"}},{"html_id":"connection:Connection-instance-method","name":"connection","abstract":true,"location":{"filename":"src/db/transaction.cr","line_number":18,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L18"},"def":{"name":"connection","return_type":"Connection","visibility":"Public","body":""}},{"html_id":"release_from_nested_transaction-instance-method","name":"release_from_nested_transaction","abstract":true,"location":{"filename":"src/db/transaction.cr","line_number":35,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L35"},"def":{"name":"release_from_nested_transaction","visibility":"Public","body":""}},{"html_id":"rollback-instance-method","name":"rollback","doc":"rollbacks the current transaction","summary":"

rollbacks the current transaction

","abstract":false,"location":{"filename":"src/db/transaction.cr","line_number":26,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/transaction.cr#L26"},"def":{"name":"rollback","visibility":"Public","body":"close!"}}]}]},{"html_id":"db/Enum","path":"Enum.html","kind":"struct","full_name":"Enum","name":"Enum","abstract":true,"superclass":{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},"ancestors":[{"html_id":"db/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"db/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"db/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/db/result_set.cr","line_number":156,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L156"}],"repository_name":"db","program":false,"enum":false,"alias":false,"const":false,"included_modules":[{"html_id":"db/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"}],"doc":"Enum is the base type of all enums.\n\nAn enum is a set of integer values, where each value has an associated name. For example:\n\n```\nenum Color\n Red # 0\n Green # 1\n Blue # 2\nend\n```\n\nValues start with the value `0` and are incremented by one, but can be overwritten.\n\nTo get the underlying value you invoke value on it:\n\n```\nColor::Green.value # => 1\n```\n\nEach constant (member) in the enum has the type of the enum:\n\n```\ntypeof(Color::Red) # => Color\n```\n\n### Flags enum\n\nAn enum can be marked with the `@[Flags]` annotation. This changes the default values:\n\n```\n@[Flags]\nenum IOMode\n Read # 1\n Write # 2\n Async # 4\nend\n```\n\nAdditionally, some methods change their behaviour.\n\n### Enums from integers\n\nAn enum can be created from an integer:\n\n```\nColor.new(1).to_s # => \"Green\"\n```\n\nValues that don't correspond to enum's constants are allowed: the value\nwill still be of type Color, but when printed you will get the underlying value:\n\n```\nColor.new(10).to_s # => \"10\"\n```\n\nThis method is mainly intended to convert integers from C to enums in Crystal.\n\n### Question methods\n\nAn enum automatically defines question methods for each member, using\n`String#underscore` for the method name.\n* In the case of regular enums, this compares by equality (`==`).\n* In the case of flags enums, this invokes `includes?`.\n\nFor example:\n\n```\ncolor = Color::Blue\ncolor.red? # => false\ncolor.blue? # => true\n\nmode = IOMode::Read | IOMode::Async\nmode.read? # => true\nmode.write? # => false\nmode.async? # => true\n```\n\nThis is very convenient in `case` expressions:\n\n```\ncase color\nwhen .red?\n puts \"Got red\"\nwhen .blue?\n puts \"Got blue\"\nend\n```\n\n### Changing the Base Type\n\nThe type of the underlying enum value is `Int32` by default, but it can be changed to any type in `Int::Primitive`.\n\n```\nenum Color : UInt8\n Red\n Green\n Blue\nend\n\nColor::Red.value # : UInt8\n```","summary":"

Enum is the base type of all enums.

","constructors":[{"html_id":"new(rs:DB::ResultSet):self-class-method","name":"new","abstract":false,"args":[{"name":"rs","external_name":"rs","restriction":"DB::ResultSet"}],"args_string":"(rs : DB::ResultSet) : self","args_html":"(rs : DB::ResultSet) : self","location":{"filename":"src/db/result_set.cr","line_number":157,"url":"https://github.com/crystal-lang/crystal-db/blob/v0.13.0/src/db/result_set.cr#L157"},"def":{"name":"new","args":[{"name":"rs","external_name":"rs","restriction":"DB::ResultSet"}],"return_type":"self","visibility":"Public","body":"index = rs.next_column_index\ncase value = rs.read\nwhen String\n parse(value)\nwhen Int\n from_value(value)\nelse\n raise(DB::ColumnTypeMismatchError.new(context: \"#{self}.new(rs : DB::ResultSet)\", column_index: index, column_name: rs.column_name(index), column_type: value.class.to_s, expected_type: \"String | Int\"))\nend\n"}}]}]}}