prepare/exec a statement

dummy driver that parses the query
initial type support for result_sets
This commit is contained in:
Brian J. Cardiff 2016-01-28 20:31:35 -03:00
parent cc1545a58e
commit 4dd0312934
7 changed files with 145 additions and 5 deletions

View file

@ -14,3 +14,5 @@ module DB
end
require "./driver"
require "./statement"
require "./result_set"

View file

@ -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
View 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
View file

@ -0,0 +1,8 @@
module DB
abstract class Statement
def initialize(@driver)
end
abstract def exec(*args) : ResultSet
end
end