Commit graph

157 commits

Author SHA1 Message Date
Brian J. Cardiff
039035a397 fix #scalar queries where not handled with retry connection pool logic 2016-12-16 11:56:27 -03:00
Brian J. Cardiff
8e8d8024f9 bump version 0.3.1 2016-12-15 14:47:10 -03:00
Brian J. Cardiff
2ca60ba43f Add ConnectionRefused exception
* required to fix retry+connection initialization corner case.
2016-12-15 14:40:56 -03:00
Brian J. Cardiff
4c74e6c9da bump version 0.3.0 2016-12-14 15:22:23 -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
d7ccecae9b minimal docs for transactions 2016-12-14 12:13:46 -03:00
Brian J. Cardiff
ed3ed71501 allow raise after explicit rollback within #transaction(&block) 2016-12-14 11:37:49 -03:00
Brian J. Cardiff
dc26498948 unwrap args 2016-12-14 11:32:53 -03:00
Brian J. Cardiff
c6b6517145 add connection.object_id to savepoint names.
s/crystal/cr/ to shorten a bit the name.
2016-12-14 11:07:17 -03:00
Brian J. Cardiff
c491bd8962 add nested transaction with savepoints 2016-12-13 16:47:23 -03:00
Brian J. Cardiff
9bde76865e add todo for corner case of transaction(&block) 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
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
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
543592a337 make pool_prepared_statements always prepare statement in connection 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
Ary Borenszweig
73108c169e v0.2.2 2016-12-06 23:33:27 -03:00
Ary Borenszweig
2073a1de91 Use Slice.empty 2016-12-06 23:27:15 -03:00
Brian J. Cardiff
cd10dabba2 default max_pool_size to 0 = unlimited 2016-11-13 18:21:05 -03:00
Brian J. Cardiff
3a7c801ece allow new connections right away if pool can be increased 2016-10-22 19:14:18 -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
0735870418 bump version 0.2.0
version 0.1.1 should be yanked. it's not backward compatible with 0.1.0.
2016-10-20 18:41:57 -03:00
Gustavo Giráldez
d7fdf1eada Release DB connection if an exception occurs during execution of a query 2016-09-28 16:45:38 -03:00
Ary Borenszweig
4f724475e0 Fixed module reference inside macro 2016-09-28 14:46:34 -03:00
Ary Borenszweig
ae6a68f00e Use forall 2016-09-19 19:20:18 -03:00
Brian J. Cardiff
751be7aa6a Merge branch 'feature/pool'
Conflicts:
	src/db/error.cr
2016-09-13 01:42:24 -03:00
Brian J. Cardiff
a62c90d092 remove connection from pool if explicitly closed 2016-09-13 01:36:49 -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
2db12d99f5 fix formatting issues 2016-09-06 13:24:57 -03:00
Brian J. Cardiff
6745ea956f migrate to crystal 0.19
* select keyword hangs so Channel.select is used still
2016-09-04 20:11:50 -03:00
Brian J. Cardiff
d3606831f3 Use select to distinguish between timeout and resource availability 2016-09-02 17:27:22 -03:00
Brian J. Cardiff
47e7d826e8 Add connection retry logic to connection pool 2016-08-31 17:32:01 -03:00
Brian J. Cardiff
dbf7c94ef4 release references to resources in pool. 2016-08-31 14:45:32 -03:00
Brian J. Cardiff
9c9176608d avoid caching statements in pool_statement
Only the connections where it was prepared need to be cached.
The connections already have a statement cache based on the query
2016-08-30 16:40:52 -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
6e94536a91 clean up forward declaration of Database and Statement 2016-08-29 16:48:59 -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
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
bed461c01b allow connection initialization 2016-08-18 00:55:43 -03:00
Ary Borenszweig
b5112d9a48 Add ResultSet#column_names. Fixes #11 2016-07-17 21:50:52 -03:00
Ary Borenszweig
1a4622ee59 Allow passing named arguments to DB.mapping 2016-07-15 11:54:09 -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
Brian J. Cardiff
b8cabee956 surround waiting_resource counter with a mutex for future thread support. 2016-07-07 14:48:58 -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
9ca0b19d9e Support mappable classes in query_one and query_all methods 2016-07-04 12:46:45 -03:00
Santiago Palladino
99352d9d2d Remove unneeded typecast when advancing a column in mapping macro 2016-07-04 12:44:31 -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
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
Santiago Palladino
5773faaa5c Enumerate columns in result_set 2016-07-04 11:11:21 -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
Ary Borenszweig
72431bb1d8 Make sure to release a statmenet in case of an exception 2016-06-29 15:08:53 -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
6838784f7b fix #1. avoid marking as closed if do_close raise exception 2016-06-24 10:54:30 -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
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
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
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
9f3f0a9836 #5 remove read_object. allow read / read? to receive any type 2016-06-21 12:10:09 -03:00
Brian J. Cardiff
0daa1c18d7 DRY DB::TYPES and DB::Any 2016-06-21 12:08:51 -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
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
6ee8c90ba7 forward declarations for docrystal.org (?) 2016-02-26 00:13:29 -03:00
Brian J. Cardiff
c6e2a51482 add readme and version 2016-02-25 23:53:23 -03:00
Brian J. Cardiff
44559f6f95 move spec and src files to a shardy way 2016-02-25 22:37:10 -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
2cb37d374c ensure db is closed after block
avoid GC Warning
2016-02-25 22:27:42 -03:00
Brian J. Cardiff
ee21fcfea6 update docs 2016-02-25 22:27:42 -03:00
Brian J. Cardiff
0cb7adabdb full type name in restriction 2016-02-25 22:27:42 -03:00
Brian J. Cardiff
4ed7f28fe6 ensure exec and scalar release connection
ensure exec, query can be executed with Enumerable(Any)
update db doc sample
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
562d5076bf use URI as connection string 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
67fe5c9aae leave a single scalar value returns DB::Any 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
1fb0b8a82b add ResultSet#exec to ensure the query is performed. By default generates a move_next. 2016-02-25 22:25:54 -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