Commit Graph

33 Commits

Author SHA1 Message Date
Brian J. Cardiff c106775ea9
Simplifications and performance improvements (#200)
* Add pool_concurrency_test manual spec

Add MT connection count without Mutex

* Drop checkout_some, simpler pool_prepared statement

* Make pool statement a struct

* Drop StringKeyCache mutex

The StringKeyCache is now only used inside a connection. It's assumed that connections are not used concurrently with multiple queries.

* Drop do_close in pool statements

* Add specs and update comment

* Fix typo
2023-12-08 19:06:41 -03:00
Brian J. Cardiff d3dd978e24
Allow statements to auto close when consumed if no cache (#198) 2023-11-29 18:39:44 -03:00
Brian J. Cardiff 9471b33ffe
Fix max_idle_pool_size race condition (#186)
* Add Fiber.yield to dummy driver to mimic real drivers IO

* Add manual load test file

* Fix race condition

* Drop unused code

* Less state, less bugs

* Update spec/manual/load_test.cr

Co-authored-by: Beta Ziliani <beta@manas.tech>

---------

Co-authored-by: Beta Ziliani <beta@manas.tech>
2023-07-31 11:04:18 -03:00
Brian J. Cardiff f13846b133
Refactor connection factory (#181)
* Start moving out URI from ConnectionContext

Create connections with an initial context. Database will set itself as context after connection has been created

* Migrate to simpler/decoupled factory in driver

This allows more freedom on how the connection is created. It will no longer need to have an explicit reference to the connection URI

* Introduce DB::Connection::Options

Move prepared_statements out from ConnectionContext

* Delegate options parsing to driver

DRY parsing connection options for database

* Introduce DB::Pool::Options

* Rename Driver#connection_pool_options to pool_options

* Drop driver getter from database

* Drop uri getter from database

* Add public Database#initialize method

* Drop :nodoc: Database#initialize

* Pass spec helper explicitly (to access methods within each spec)

* Update docs

* Update src/db/pool.cr

Co-authored-by: Beta Ziliani <beta@manas.tech>

* Use ConnectionBuilder instead of procs

* Fix inferred type when there is a single concrete connection type

* Update src/db/driver.cr

Co-authored-by: Beta Ziliani <beta@manas.tech>

---------

Co-authored-by: Beta Ziliani <beta@manas.tech>
2023-06-22 22:03:08 -03:00
Jamie Gaskins 167b55966e
Allow the use of enums (#168) 2022-10-26 16:06:14 +02: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
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 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
Brian J. Cardiff ac083f430a Updates for crystal 0.24.0 2017-12-29 20:13:34 -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 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 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 4721ecbf6b make Connection#prepared_statements? readonly 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 47e7d826e8 Add connection retry logic to connection pool 2016-08-31 17:32:01 -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 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 a2c22c16cf allow DB to use a connection pool.
allow Driver to parse connection pool options for extensibility.
fix waiting_resource counter after a timeout was generated.
2016-07-07 15:50:09 -03:00
Santiago Palladino 552b6e12b4 Rebase to latest DB version and upgrade to Crystal 0.18 2016-07-04 12:13:39 -03:00
Santiago Palladino 6b065bd6b6 Handle different number of columns in dummy driver
Number of cols is inferred from the number of fields in the first row.
2016-07-04 11:15:04 -03:00
Ary Borenszweig 9c88f718e8 Require ResultSet to just implement `read`, optionally implementing `read(T.class)`. Fixes #5 2016-06-30 09:46:25 -03:00
Brian J. Cardiff 8025ecaa13 update Slice(UInt8) to Bytes 2016-06-22 14:10:09 -03:00
Brian J. Cardiff 11e24e1c65 #5 Make sure queries (insert and query) work with any type 2016-06-22 00:44:16 -03:00
Brian J. Cardiff c5d7778a0d update DB::ExecResult#rows_affected to Int64 2016-06-21 18:31:13 -03:00
Brian J. Cardiff 76e3a35d59 allow exec to receive any object arguments 2016-06-21 10:55:44 -03:00
Brian J. Cardiff 3464a1d1cc allow query to receive any object arguments 2016-06-21 10:55:41 -03:00
Brian J. Cardiff d69555b372 make Nil a proper column type 2016-06-21 10:53:34 -03:00
Ary Borenszweig f834b0f8a6 Updated to Crystal 0.17.4 2016-06-16 12:16:39 -03:00
Brian J. Cardiff 44559f6f95 move spec and src files to a shardy way 2016-02-25 22:37:10 -03:00
Renamed from spec/std/db/dummy_driver.cr (Browse further)