diff options
Diffstat (limited to 'src/database.nim')
-rw-r--r-- | src/database.nim | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/database.nim b/src/database.nim index 1ffc0df..37ef8b4 100644 --- a/src/database.nim +++ b/src/database.nim @@ -1,6 +1,8 @@ -import tiny_sqlite import std / [options, times] +import tiny_sqlite +import uuids + import dbUtils const migrations = [ @@ -47,7 +49,7 @@ proc Migrate*(db: DbConn): bool {.raises: [].} = type ShortUrl* = object ID*: int - Token*: string + Token*: UUID Title*: string Url*: string Created*: DateTime @@ -58,11 +60,11 @@ proc AddUrl*(db: DbConn, url: ShortUrl) {.raises: [SqliteError].} = INSERT INTO url(token, title, url, created, expires) VALUES (?, ?, ?, ?, ?); """) - stmt.exec(url.Token, url.Title, url.Url, url.Created, $url.Expires) + stmt.exec($url.Token, url.Title, url.Url, url.Created, $url.Expires) -proc GetUrl*(db: DbConn, token: string): ref ShortUrl {.raises: [SqliteError].} = +proc GetUrl*(db: DbConn, token: UUID): ref ShortUrl {.raises: [SqliteError].} = let stmt = db.stmt("SELECT id, title, url, created, expires FROM url WHERE token = ?") - for row in stmt.iterate(token): + for row in stmt.iterate($token): new(result) result.ID = row[0].fromDbValue(int) result.Token = token |