Merged branch master into feature/pool

This commit is contained in:
Brian J. Cardiff 2016-08-29 12:57:42 -03:00
commit 3c91978d36
8 changed files with 39 additions and 15 deletions

View file

@ -138,4 +138,7 @@ module DB
end
end
macro mapping(**properties)
::DB.mapping({{properties}})
end
end

View file

@ -35,7 +35,7 @@ module DB
# end
# ```
def query(query, *args)
prepare query, &.query(*args)
prepare(query).query(*args)
end
# Executes a *query* and yields a `ResultSet` with the results.
@ -200,23 +200,13 @@ module DB
# Performs the `query` and returns an `ExecResult`
def exec(query, *args)
prepare query, &.exec(*args)
prepare(query).exec(*args)
end
# Performs the `query` and returns a single scalar value
# puts db.scalar("SELECT MAX(name)").as(String) # => (a String)
def scalar(query, *args)
prepare query, &.scalar(*args)
end
private def prepare(query)
stm = prepare(query)
begin
yield stm
rescue ex
stm.release_connection
raise ex
end
prepare(query).scalar(*args)
end
end
end

View file

@ -61,6 +61,11 @@ module DB
# Returns the name of the column in `index` 0-based position.
abstract def column_name(index : Int32) : String
# Returns the name of the columns.
def column_names
Array(String).new(column_count) { |i| column_name(i) }
end
# Reads the next column value
abstract def read

View file

@ -74,9 +74,9 @@ module DB
end
private def perform_exec_and_release(args : Enumerable) : ExecResult
res = perform_exec(args)
return perform_exec(args)
ensure
release_connection
res
end
protected abstract def perform_query(args : Enumerable) : ResultSet