mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Add type argument to QueryMethods module (#108)
This commit is contained in:
parent
0100b47754
commit
adc755e5e4
10 changed files with 30 additions and 30 deletions
|
@ -36,7 +36,7 @@ module DB
|
|||
end
|
||||
|
||||
# :nodoc:
|
||||
def fetch_or_build_prepared_statement(query)
|
||||
def fetch_or_build_prepared_statement(query) : Statement
|
||||
@statements_cache.fetch(query) { build_prepared_statement(query) }
|
||||
end
|
||||
|
||||
|
@ -46,7 +46,7 @@ module DB
|
|||
# :nodoc:
|
||||
abstract def build_unprepared_statement(query) : Statement
|
||||
|
||||
def begin_transaction
|
||||
def begin_transaction : Transaction
|
||||
raise DB::Error.new("There is an existing transaction in this connection") if @transaction
|
||||
@transaction = true
|
||||
create_transaction
|
||||
|
|
|
@ -37,7 +37,7 @@ module DB
|
|||
getter pool
|
||||
|
||||
# Returns the uri with the connection settings to the database
|
||||
getter uri
|
||||
getter uri : URI
|
||||
|
||||
getter? prepared_statements : Bool
|
||||
|
||||
|
@ -86,17 +86,17 @@ module DB
|
|||
end
|
||||
|
||||
# :nodoc:
|
||||
def fetch_or_build_prepared_statement(query)
|
||||
def fetch_or_build_prepared_statement(query) : PoolStatement
|
||||
@statements_cache.fetch(query) { build_prepared_statement(query) }
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
def build_prepared_statement(query)
|
||||
def build_prepared_statement(query) : PoolStatement
|
||||
PoolPreparedStatement.new(self, query)
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
def build_unprepared_statement(query)
|
||||
def build_unprepared_statement(query) : PoolStatement
|
||||
PoolUnpreparedStatement.new(self, query)
|
||||
end
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ module DB
|
|||
|
||||
# builds a statement over a real connection
|
||||
# the connection is registered in `@connections`
|
||||
private def build_statement
|
||||
private def build_statement : Statement
|
||||
clean_connections
|
||||
conn, existing = @db.checkout_some(@connections)
|
||||
begin
|
||||
|
|
|
@ -14,7 +14,7 @@ module DB
|
|||
end
|
||||
|
||||
# builds a statement over a real connection
|
||||
private def build_statement
|
||||
private def build_statement : Statement
|
||||
conn = @db.pool.checkout
|
||||
begin
|
||||
conn.unprepared.build(@query)
|
||||
|
|
|
@ -17,9 +17,9 @@ module DB
|
|||
#
|
||||
# Including `QueryMethods` requires a `build(query) : Statement` method that is not expected
|
||||
# to be called directly.
|
||||
module QueryMethods
|
||||
module QueryMethods(Stmt)
|
||||
# :nodoc:
|
||||
abstract def build(query) : Statement
|
||||
abstract def build(query) : Stmt
|
||||
|
||||
# Executes a *query* and returns a `ResultSet` with the results.
|
||||
# The `ResultSet` must be closed manually.
|
||||
|
|
|
@ -8,7 +8,7 @@ module DB
|
|||
#
|
||||
# This module serves for dsl reuse over session like objects.
|
||||
module SessionMethods(Session, Stmt)
|
||||
include QueryMethods
|
||||
include QueryMethods(Stmt)
|
||||
|
||||
# Returns whether by default the statements should
|
||||
# be prepared or not.
|
||||
|
@ -49,7 +49,7 @@ module DB
|
|||
end
|
||||
|
||||
struct PreparedQuery(Session, Stmt)
|
||||
include QueryMethods
|
||||
include QueryMethods(Stmt)
|
||||
|
||||
def initialize(@session : Session)
|
||||
end
|
||||
|
@ -60,7 +60,7 @@ module DB
|
|||
end
|
||||
|
||||
struct UnpreparedQuery(Session, Stmt)
|
||||
include QueryMethods
|
||||
include QueryMethods(Stmt)
|
||||
|
||||
def initialize(@session : Session)
|
||||
end
|
||||
|
|
|
@ -63,12 +63,12 @@ module DB
|
|||
end
|
||||
|
||||
# See `QueryMethods#exec`
|
||||
def exec
|
||||
def exec : DB::ExecResult
|
||||
perform_exec_and_release(Slice(Any).empty)
|
||||
end
|
||||
|
||||
# See `QueryMethods#exec`
|
||||
def exec(args : Array)
|
||||
def exec(args : Array) : DB::ExecResult
|
||||
perform_exec_and_release(args)
|
||||
end
|
||||
|
||||
|
@ -79,12 +79,12 @@ module DB
|
|||
end
|
||||
|
||||
# See `QueryMethods#query`
|
||||
def query
|
||||
def query : DB::ResultSet
|
||||
perform_query_with_rescue Tuple.new
|
||||
end
|
||||
|
||||
# See `QueryMethods#query`
|
||||
def query(args : Array)
|
||||
def query(args : Array) : DB::ResultSet
|
||||
perform_query_with_rescue args
|
||||
end
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ module DB
|
|||
end
|
||||
|
||||
class TopLevelTransaction < Transaction
|
||||
getter connection
|
||||
getter connection : Connection
|
||||
# :nodoc:
|
||||
property savepoint_name : String? = nil
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue