summaryrefslogtreecommitdiff
path: root/src/dbUtils.nim
diff options
context:
space:
mode:
authorJulien Dessaux2021-10-22 17:59:44 +0200
committerJulien Dessaux2021-10-25 15:22:24 +0200
commitad9b9c0f7bd4d95ddc54462970d33d92bab9392c (patch)
treeb8d130d728fda49c64b6e021da31afb2418b78a0 /src/dbUtils.nim
parentInitial import (diff)
downloadshort-ad9b9c0f7bd4d95ddc54462970d33d92bab9392c.tar.gz
short-ad9b9c0f7bd4d95ddc54462970d33d92bab9392c.tar.bz2
short-ad9b9c0f7bd4d95ddc54462970d33d92bab9392c.zip
Added a functionning url shortening service
Diffstat (limited to 'src/dbUtils.nim')
-rw-r--r--src/dbUtils.nim13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/dbUtils.nim b/src/dbUtils.nim
new file mode 100644
index 0000000..bdbcf14
--- /dev/null
+++ b/src/dbUtils.nim
@@ -0,0 +1,13 @@
+import std/times
+import tiny_sqlite
+
+proc toDbValue*(t: DateTime): DbValue {.raises: [].}=
+ DbValue(kind: sqliteText, strVal: $t)
+
+proc fromDbValue*(value: DbValue, T: typedesc[DateTime]): DateTime {.raises: [].}=
+ try:
+ case value.kind:
+ of sqliteText: return times.parse(value.strVal, "yyyy-MM-dd'T'HH:mm:sszzz")
+ else: return
+ except TimeParseError:
+ return