Commit graph

96 commits

Author SHA1 Message Date
Johannes Müller
5a7d27e0c5
Improve DB::MappingException usage (#129) 2021-10-12 20:51:53 -03:00
Jeremy Woertink
b1299fcada
Raise a specific class error instead of string literal (#156)
* Raise a specific class error instead of string literal when the type returned doesn't match the type expected. Allows for drivers to catch the specific error.

* Add ResultSet#next_column_index

* Add shared specs for next_column_index

* Add properties to ColumnTypeMismatchError

* Add shared specs for ColumnTypeMismatchError

* Fix specs

Co-authored-by: Brian J. Cardiff <bcardiff@gmail.com>
2021-10-12 20:49:26 -03:00
Stephen von Takach
a25f33611c
feat(error): close resources on resource lost (#155) 2021-09-10 08:36:01 -03:00
Stephen von Takach
6dc3f2dd6f
fix(pool): returning closed resources to the pool (#154) 2021-09-06 19:02:43 -03:00
Brian J. Cardiff
7253551849
Add logging for executing queries (#134)
* Add logging for executing queries

Arguments are translated to Log::Metadata::Value via DB::Statement#arg_to_log method.

DB::Statement#before_query_or_exec & after_query_or_exec protected methods can be used to hook and run around the statement execution

* Move the metadata converter to a module

* Replace before/after with def_around_query_or_exec macro

* Update src/db/enumerable_concat.cr

Co-authored-by: Ary Borenszweig <asterite@gmail.com>

Co-authored-by: Ary Borenszweig <asterite@gmail.com>
2020-09-25 14:49:50 -03:00
Johannes Müller
fad9e70353
Fix mutex deadlock in setup_connection (#128)
Adds auto_release = false in setup_connection to avoid trying to release
the connection to the pool before it has been added.
2020-09-14 10:55:18 -03:00
Jamie Gaskins
291b65b853
Allow DB::Pool to be used a generic connection pool (#131)
* Allow DB::Pool to be a generic connection pool

* Use fully qualified class name for consistency

Co-authored-by: Brian J. Cardiff <bcardiff@gmail.com>

* Wrap only the necessary code in an `ensure`

* Add spec for http client pool

* Fix ICE in crystal-sqlite3

Co-authored-by: Brian J. Cardiff <bcardiff@gmail.com>
2020-09-14 10:49:00 -03:00
Brian J. Cardiff
511fe20253
Use DB::NoResultsError on QueryMethods (#125) 2020-04-06 18:36:37 -03:00
Brian J. Cardiff
af200eac54 Comply exhaustive case check
Comply exhaustive case check
2020-04-02 12:34:27 -03:00
Jeremy Woertink
f08a4da60a
Add NoResultsError (#121) 2020-02-17 22:04:23 +01:00
Nick Clifford
e1832fc359 Add DB::Serializable (#115) 2019-10-31 11:34:23 -03:00
Johannes Müller
b3898ae2a2 Statement#exec and #query require named argument for array values (#110)
This change allows to use an array as single argument for #exec and
 #query and #scalar methods. Before it was shadowed by the *args splat overload.
2019-09-20 17:23:09 -03:00
Brian J. Cardiff
adc755e5e4
Add type argument to QueryMethods module (#108) 2019-08-02 11:54:52 -03:00
Rob David
c54fab415e Fixes query_one? handling no rows (#86) 2018-07-11 00:47:39 +01:00
Brian J. Cardiff
ac083f430a Updates for crystal 0.24.0 2017-12-29 20:13:34 -03:00
Arthur Poulet
d55a34e851 Allow query results to be read as named tuples directly (#56) 2017-12-29 19:32:25 -03:00
Brian J. Cardiff
9b03aa6535 Release connection when unprepared statements can't be built
Add specs
Fix typo in docs
2017-09-07 19:21:36 -03:00
Brian J. Cardiff
39e17f82ca Add #query_each . Fixes #18 2017-04-10 12:48:48 -03:00
Brian J. Cardiff
bb3203301b Deal with unexpected ResultSet#read types during runtime. 2017-04-06 15:55:13 -03:00
Brian J. Cardiff
385cf70a8a Introduce DB::ConnectionContext (#44)
* make Database a ConnectionContext.
* introduce SingleConnectionContext for independant connections.
* add `DB#connect` to create non pooled connections.
2017-03-20 15:08:30 -03:00
Brian J. Cardiff
c63ea48748 Close result_set with using Mapping.from_rs 2017-03-20 13:54:39 -03:00
Brian J. Cardiff
2886c207e0 Add support for nillables with T | Nil syntax. 2017-03-06 12:18:04 -03:00
RX14
0797ce72a3 Allow nilable types in DB.mapping
Previously, using a Nilable type in DB.mapping instead of nilable: true would
fail with a nil assertion error.
2017-02-15 16:09:01 +00:00
Brian J. Cardiff
3fa1eac6c5 Add Database#checkout, Connection#release for non block connection use (#38) 2017-02-12 16:30:32 -03:00
Brian J. Cardiff
09b8997636 Add before_checkout/after_release callbacks for resources in pool (#36)
add auto_release to DB::Connection (default true on each pool checkout).
fixes #35.
2017-01-16 16:47:58 -03:00
Brian J. Cardiff
ed3ed71501 allow raise after explicit rollback within #transaction(&block) 2016-12-14 11:37:49 -03:00
Brian J. Cardiff
882253bf4a specs to ensure connection is not returned to pool in nested transaction 2016-12-14 10:57:12 -03:00
Brian J. Cardiff
c491bd8962 add nested transaction with savepoints 2016-12-13 16:47:23 -03:00
Brian J. Cardiff
751f8b26ac Transactions
* dsl, state checks
* define transaction sql commands in connection
2016-12-13 16:47:23 -03:00
Brian J. Cardiff
da2831c17d validate boolean option in connection string. proper downcase. 2016-12-07 01:50:06 -03:00
Brian J. Cardiff
4721ecbf6b make Connection#prepared_statements? readonly 2016-12-07 01:50:06 -03:00
Brian J. Cardiff
543592a337 make pool_prepared_statements always prepare statement in connection 2016-12-07 01:50:06 -03:00
Brian J. Cardiff
2cab0b37f5 refactor prepared and unprepared pool statements 2016-12-07 01:50:06 -03:00
Brian J. Cardiff
0593f63dbb add pool unprepared statements
unprepared statements are executed in any free connection of the pool at the moment of executing them
2016-12-07 01:50:06 -03:00
Brian J. Cardiff
9ef9d19d1d add prepared_statements option to database
* use ?prepared_statements=true|false on connection string (default: true)
* make inmutable state in database
* make mutable state in connection
* change Connection#build to use the current prepared_statements flag to build prepared or unprepared statements.
2016-12-07 01:50:06 -03:00
Brian J. Cardiff
fe0ed55ef9 introduce unprepared statements
* rename QueryMethods#prepare to QueryMethods#build
* rename Connection#build_statement to Connection#build_prepared_statement
* add Connection#build_unprepared_statement
* add Connection #prepared and #unprepared dsl methods
2016-12-07 01:50:06 -03:00
Brian J. Cardiff
cd10dabba2 default max_pool_size to 0 = unlimited 2016-11-13 18:21:05 -03:00
Brian J. Cardiff
3a7c801ece allow new connections right away if pool can be increased 2016-10-22 19:14:18 -03:00
Ary Borenszweig
56aa10c54d Better error message when requesting a driver that was not found. Fixes #21 2016-10-21 11:24:32 -03:00
Brian J. Cardiff
751be7aa6a Merge branch 'feature/pool'
Conflicts:
	src/db/error.cr
2016-09-13 01:42:24 -03:00
Brian J. Cardiff
2db12d99f5 fix formatting issues 2016-09-06 13:24:57 -03:00
Brian J. Cardiff
47e7d826e8 Add connection retry logic to connection pool 2016-08-31 17:32:01 -03:00
Brian J. Cardiff
f568e4506d add cache of pool statements per query
refactor/reuse connection statement cache
2016-08-30 16:20:18 -03:00
Brian J. Cardiff
75aa821f5f make Database return PoolStatement
create StatementMethods for common interface between Statement and PoolStatment.
2016-08-29 16:56:34 -03:00
Brian J. Cardiff
6a0a450622 make statement_specs run over a single connection 2016-08-29 16:50:37 -03:00
Brian J. Cardiff
8d891a5a4e changes needed due to 3c91978d36
add posibility to inspect availability of a resource in a pool (testing only)
allow access to internal connection pool of db (testing only)
2016-08-29 13:14:47 -03:00
Brian J. Cardiff
3c91978d36 Merged branch master into feature/pool 2016-08-29 12:57:42 -03:00
Brian J. Cardiff
325fa9d4ae ensure the connection is released after exec
avoid releasing connection twice on exec.
avoid releasing connection when QueryMethod#query is blockless called.
2016-08-29 01:23:20 -03:00
Brian J. Cardiff
bed461c01b allow connection initialization 2016-08-18 00:55:43 -03:00
Ary Borenszweig
b5112d9a48 Add ResultSet#column_names. Fixes #11 2016-07-17 21:50:52 -03:00