Commit graph

41 commits

Author SHA1 Message Date
Brian J. Cardiff
285e865e3a
Allow prepared_statements_cache=false option to disable prepared statements cache (#194)
* Add prepared_statements_cache in connection to opt-out

* Honor prepared_statements_cache option in database also
2023-11-03 23:04:14 -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
eaddae7d71
Add docs for DB::Database#setup_connection (#139) 2020-10-27 12:55:06 -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
Brian J. Cardiff
adc755e5e4
Add type argument to QueryMethods module (#108) 2019-08-02 11:54:52 -03:00
Brian J. Cardiff
0100b47754
Documentation improvements (#107)
Closes #89
2019-07-02 10:01:17 -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
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
d7ccecae9b minimal docs for transactions 2016-12-14 12:13:46 -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
d55b088216 Refactor Database and Connection dsl methods. Update docs. 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
ea2a107069 allow releasing connections of the pool from pool_statements
remove old connections from PoolStatement::@connections either disposed or closed connections
2016-09-12 14:35:21 -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
09b3b4bc01 minor code cleanup 2016-08-30 15:22:27 -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
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
bed461c01b allow connection initialization 2016-08-18 00:55:43 -03:00
Ary Borenszweig
1cce4685ff Make DB::Pool accept a block 2016-07-11 15:38:31 -03:00
Ary Borenszweig
fff67e86a0 Fix using_connection 2016-07-11 12:56:40 -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
Ary Borenszweig
2fc3f66a00 Make sure to return the connection to the pool in case of an exception preparing a query 2016-06-29 15:01:26 -03:00
Brian J. Cardiff
f836bbfccb add Database#using_connection to get a connection from the pool and return it when work is done. 2016-06-23 17:27:30 -03:00
Ary Borenszweig
f834b0f8a6 Updated to Crystal 0.17.4 2016-06-16 12:16:39 -03:00
Brian J. Cardiff
2cb37d374c ensure db is closed after block
avoid GC Warning
2016-02-25 22:27:42 -03:00
Brian J. Cardiff
d45427dfdd expose database in connection
get/return from pool while result set is been used. still single connection pool
2016-02-25 22:27:42 -03:00
Brian J. Cardiff
562d5076bf use URI as connection string 2016-02-25 22:27:42 -03:00
Brian J. Cardiff
782a2ee0e2 hide #prepare from api. 2016-02-25 22:27:42 -03:00
Brian J. Cardiff
d01da912f7 code review notes
close / do_close in result_set
avoid closing statements
remove named arguments
refactor positioned arguments query
2016-02-25 22:25:55 -03:00
Brian J. Cardiff
fd804dd592 switch to 0-pased positional arguments
add docs, many docs
2016-02-25 22:25:55 -03:00
Brian J. Cardiff
a96776e336 use connection_string as database configuration instead of a hash 2016-02-25 22:25:55 -03:00
Brian J. Cardiff
8c0313a306 add Connection#last_inserted_id
extract QueryMethods modules and use it in Database and Connection
"add" finalize methods, but they cause GC warnings
2016-02-25 22:25:55 -03:00
Brian J. Cardiff
683e6bdfa7 major db refactor for a better api.
`#query`, `#exec`, `#scalar`, `#scalar?` as main query methods from `Database`
blocks overrides that ensure statements are closed.
2016-02-25 22:25:54 -03:00
Brian J. Cardiff
caf2676aad column_count and column_names
close result_set and statements
main entry points for exec_non_query and exec_query closing them when ready
2016-02-25 22:25:54 -03:00
Brian J. Cardiff
1572062501 introduce database as driver wrapper.
expose list of types to support by the drivers implementors.
deal with nilable types with `#read?(T.class) : T?` methods.
change `#has_next` to `#move_next`
2016-02-25 22:25:54 -03:00