Commit graph

29 commits

Author SHA1 Message Date
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
Brian J. Cardiff
adc755e5e4
Add type argument to QueryMethods module (#108) 2019-08-02 11:54:52 -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
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
d55b088216 Refactor Database and Connection dsl methods. Update docs. 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
a62c90d092 remove connection from pool if explicitly closed 2016-09-13 01:36:49 -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
6e94536a91 clean up forward declaration of Database and Statement 2016-08-29 16:48:59 -03:00
Brian J. Cardiff
34ae9d5775 avoid messing with finalize cycle in Disposable.
ensure statements are closed when connection is closed
2016-06-23 22:07:59 -03:00
Brian J. Cardiff
6ee8c90ba7 forward declarations for docrystal.org (?) 2016-02-26 00:13:29 -03:00
Brian J. Cardiff
928c1517dc update to 0.12 features
clarify expected protocol with ResultSet in docs
minor refactors suggested
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
fa111fd698 add statement cache in connection.
hide methods from api
2016-02-25 22:27:42 -03:00
Brian J. Cardiff
b92d08bf74 refactor db disposables 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
6a5b2a8758 assert connection is closed after db is used.
tidy up close methods
2016-02-25 22:27:35 -03:00
Brian J. Cardiff
3598dddb65 split perform_query and perform_exec
add DB::ExecResult to have a concurrency safety exec result
remove connection string from abstract DB::Connection
2016-02-25 22:25:55 -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