Commit Graph

31 Commits

Author SHA1 Message Date
Johannes Müller 340b6e4b9a
Add reference to `DB::Serializable` in docs (#197) 2023-11-09 08:22:51 -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
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
Brian J. Cardiff f128d6ddf3
Update README.md and docs for dynamic args (#117) 2020-01-14 10:29:54 -03: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 0100b47754
Documentation improvements (#107)
Closes #89
2019-07-02 10:01:17 -03:00
Brian J. Cardiff 28b17b7dba Update sqlite doc sample to use TEXT
Ref: #71
2017-11-13 10:56:33 -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 4e238f655f add Bool and Time to DB::Any fixes #4 closes #24 2016-12-14 15:17:40 -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 1049d95562 update readme and docs links to drivers 2016-12-13 16:46:44 -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 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
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 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 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
Brian J. Cardiff 421996b952 resource pool implementation with
* max_pool_size
* initial_pool_size
* max_idle_pool_size
* checkout_timeout
configuration options
2016-07-05 15:21:39 -03:00
Santiago Palladino 7fcedc6711 Database mapping macro
Add `from_rs` method to class to load instances from a resultset. Inspired by YAML and JSON mapping macros.
2016-07-04 11:19:16 -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
Ary Borenszweig 038ffef33a Don't use tap so return value is that of `yield` 2016-06-29 16:54:16 -03:00
Brian J. Cardiff 8025ecaa13 update Slice(UInt8) to Bytes 2016-06-22 14:10:09 -03:00
Brian J. Cardiff c5d7778a0d update DB::ExecResult#rows_affected to Int64 2016-06-21 18:31:13 -03:00
Brian J. Cardiff 0daa1c18d7 DRY DB::TYPES and DB::Any 2016-06-21 12:08:51 -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 src/db/db.cr (Browse further)