mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
prepare/exec a statement
dummy driver that parses the query initial type support for result_sets
This commit is contained in:
parent
cc1545a58e
commit
4dd0312934
7 changed files with 145 additions and 5 deletions
|
@ -14,3 +14,5 @@ module DB
|
|||
end
|
||||
|
||||
require "./driver"
|
||||
require "./statement"
|
||||
require "./result_set"
|
||||
|
|
|
@ -4,5 +4,7 @@ module DB
|
|||
|
||||
def initialize(@options)
|
||||
end
|
||||
|
||||
abstract def prepare(query) : Statement
|
||||
end
|
||||
end
|
||||
|
|
31
src/db/result_set.cr
Normal file
31
src/db/result_set.cr
Normal file
|
@ -0,0 +1,31 @@
|
|||
module DB
|
||||
abstract class ResultSet
|
||||
getter statement
|
||||
|
||||
def initialize(@statement : Statement)
|
||||
end
|
||||
|
||||
abstract def has_next : Bool
|
||||
|
||||
# def read(t : T.class) : T
|
||||
# end
|
||||
|
||||
# list datatypes that must be supported form the driver
|
||||
# implementors will override read_string
|
||||
# users will call read(String) due to overloads read(T) will be a T
|
||||
# TODO: unable to write unions (nillables)
|
||||
{% for t in [String, UInt64] %}
|
||||
def read(t : {{t}}.class) : {{t}}
|
||||
read_{{t.name.underscore}}
|
||||
end
|
||||
|
||||
protected abstract def read_{{t.name.underscore}} : {{t}}
|
||||
{% end %}
|
||||
|
||||
# def read(t : String.class) : String
|
||||
# read_string
|
||||
# end
|
||||
#
|
||||
# protected abstract def read_string : String
|
||||
end
|
||||
end
|
8
src/db/statement.cr
Normal file
8
src/db/statement.cr
Normal file
|
@ -0,0 +1,8 @@
|
|||
module DB
|
||||
abstract class Statement
|
||||
def initialize(@driver)
|
||||
end
|
||||
|
||||
abstract def exec(*args) : ResultSet
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue