Commit Graph

21 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
Johannes Müller 07c68d38e4
Fix positional parameter warnings (#173) 2022-10-20 20:48:21 +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 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 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
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 933014c1aa fix bug related to Slice(T).new(0). It was messing with the data in the stack 2016-06-23 22:36:34 -03:00
Brian J. Cardiff b2da4f3f6e allow scalar to return custom types 2016-06-23 22:19:53 -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 9f3f0a9836 #5 remove read_object. allow read / read? to receive any type 2016-06-21 12:10:09 -03:00
Brian J. Cardiff 76e3a35d59 allow exec to receive any object arguments 2016-06-21 10:55:44 -03:00
Brian J. Cardiff d4b2046a65 refactor and add specs for query without blocks 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 5b23114095 add ResultSet#read_object 2016-06-21 10:54:58 -03:00
Brian J. Cardiff 312609b722 allow specs to use multiple drivers 2016-06-21 10:54:56 -03:00