mirror of
https://gitea.invidious.io/iv-org/shard-crystal-sqlite3.git
synced 2024-08-15 00:53:26 +00:00
extend sqlite with time (as text) support.
This commit is contained in:
parent
d65575cd77
commit
497379ff81
4 changed files with 38 additions and 1 deletions
|
@ -1,2 +1,6 @@
|
|||
require "db"
|
||||
require "./sqlite3/**"
|
||||
|
||||
module SQLite3
|
||||
DATE_FORMAT = "%F %H:%M:%S.%L"
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ class SQLite3::ResultSet < DB::ResultSet
|
|||
end
|
||||
end
|
||||
|
||||
{% for t in DB::TYPES %}
|
||||
macro nilable_read_for(t)
|
||||
def read?(t : {{t}}.class) : {{t}}?
|
||||
if read_nil?
|
||||
moving_column { nil }
|
||||
|
@ -30,6 +30,10 @@ class SQLite3::ResultSet < DB::ResultSet
|
|||
read(t)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
{% for t in DB::TYPES %}
|
||||
nilable_read_for({{t}})
|
||||
{% end %}
|
||||
|
||||
def read(t : String.class) : String
|
||||
|
@ -62,6 +66,12 @@ class SQLite3::ResultSet < DB::ResultSet
|
|||
end
|
||||
end
|
||||
|
||||
def read(t : Time.class) : Time
|
||||
Time.parse read(String), SQLite3::DATE_FORMAT
|
||||
end
|
||||
|
||||
nilable_read_for Time
|
||||
|
||||
def column_count
|
||||
LibSQLite3.column_count(self)
|
||||
end
|
||||
|
|
|
@ -56,6 +56,10 @@ class SQLite3::Statement < DB::Statement
|
|||
check LibSQLite3.bind_blob(self, index, value, value.size, nil)
|
||||
end
|
||||
|
||||
private def bind_arg(index, value : Time)
|
||||
bind_arg(index, value.to_s(SQLite3::DATE_FORMAT))
|
||||
end
|
||||
|
||||
private def bind_arg(index, value)
|
||||
raise "#{self.class} does not support #{value.class} params"
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue