diff options
author | Julien Dessaux | 2021-10-29 21:13:53 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-10-29 21:13:53 +0200 |
commit | 785ef2a9135281e4ec67662ef60c27a320f22b9b (patch) | |
tree | ebe8917b9c192b80baff8879d951474fa209d783 /src/database.nim | |
parent | Added gitignore (diff) | |
download | short-785ef2a9135281e4ec67662ef60c27a320f22b9b.tar.gz short-785ef2a9135281e4ec67662ef60c27a320f22b9b.tar.bz2 short-785ef2a9135281e4ec67662ef60c27a320f22b9b.zip |
Changed for a better way to generate uuids
Diffstat (limited to '')
-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 |