Update API to handle the multiple formats of datetime Postgres might use.
This commit is contained in:
@ -2,7 +2,10 @@ import json, macros, options, sequtils, strutils, times, timeutils, unicode,
|
||||
uuids
|
||||
|
||||
const UNDERSCORE_RUNE = "_".toRunes[0]
|
||||
const PG_TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:sszz"
|
||||
const PG_TIMESTAMP_FORMATS = [
|
||||
"yyyy-MM-dd HH:mm:sszz",
|
||||
"yyyy-MM-dd HH:mm:ss'.'fffzz"
|
||||
]
|
||||
|
||||
type
|
||||
MutateClauses* = object
|
||||
@ -62,6 +65,13 @@ proc dbFormat*[T](item: T): string = return $item
|
||||
type DbArrayParseState = enum
|
||||
expectStart, inQuote, inVal, expectEnd
|
||||
|
||||
proc parsePGDatetime*(val: string): DateTime =
|
||||
var errStr = ""
|
||||
for df in PG_TIMESTAMP_FORMATS:
|
||||
try: return val.parse(df)
|
||||
except: errStr &= "\n" & getCurrentExceptionMsg()
|
||||
raise newException(ValueError, "Cannot parse PG date. Tried:" & errStr)
|
||||
|
||||
proc parseDbArray*(val: string): seq[string] =
|
||||
result = newSeq[string]()
|
||||
|
||||
@ -129,7 +139,7 @@ proc createParseStmt*(t, value: NimNode): NimNode =
|
||||
result = quote do: parseUUID(`value`)
|
||||
|
||||
elif t.getType == DateTime.getType:
|
||||
result = quote do: `value`.parse(PG_TIMESTAMP_FORMAT)
|
||||
result = quote do: parsePGDatetime(`value`)
|
||||
|
||||
elif t.getTypeInst == Option.getType:
|
||||
let innerType = t.getTypeImpl[2][0][0][1]
|
||||
|
@ -14,8 +14,8 @@ create table "api_tokens" (
|
||||
id uuid default uuid_generate_v4() primary key,
|
||||
user_id uuid not null references users (id) on delete cascade on update cascade,
|
||||
name varchar not null,
|
||||
created timestamp with time zone not null default current_timestamp,
|
||||
expires timestamp with time zone default null,
|
||||
created timestamp(0) with time zone not null default current_timestamp,
|
||||
expires timestamp(0) with time zone default null,
|
||||
hashed_token varchar not null
|
||||
);
|
||||
|
||||
@ -33,7 +33,7 @@ create table "measurements" (
|
||||
id uuid default uuid_generate_v4() primary key,
|
||||
measure_id uuid not null references measures (id) on delete cascade on update cascade,
|
||||
value integer not null,
|
||||
"timestamp" timestamp with time zone not null default current_timestamp,
|
||||
"timestamp" timestamp(0) with time zone not null default current_timestamp,
|
||||
ext_data jsonb not null default '{}'::json
|
||||
);
|
||||
|
||||
@ -44,7 +44,7 @@ create table client_log_entries (
|
||||
"scope" varchar not null,
|
||||
message varchar not null,
|
||||
stacktrace varchar not null,
|
||||
"timestamp" timestamp with time zone not null default current_timestamp
|
||||
"timestamp" timestamp(0) with time zone not null default current_timestamp
|
||||
);
|
||||
|
||||
create index client_log_entries_by_level on client_log_entries ("level");
|
||||
|
Reference in New Issue
Block a user