Forget-Me-Not/models/user.nim

34 lines
915 B
Nim
Raw Permalink Normal View History

2025-05-15 08:01:35 -05:00
#[Copyright 2025 ITwrx.
2025-05-17 09:02:52 -05:00
This file is part of Forget-Me-Not.
Forget-Me-Not is released under the GNU Affero General Public License 3.0.
2025-05-15 08:01:35 -05:00
See COPYING or <https://www.gnu.org/licenses/> for details.]#
import sqliteral, "../helpers/db"
type
User* = object
email*, password*: string
id*: int
proc getUserByEmail*(email: string): User =
{.gcsafe.}:
var user: User
for row in db1.rows(SelectUsersByEmail, email):
user.id = row.getInt(0)
user.email = row.getString(1)
user.password = row.getString(2)
return user
proc getEmailByUserId*(id: string): string =
{.gcsafe.}:
var user: User
for row in db1.rows(SelectUserById, id):
user.id = row.getInt(0)
user.email = row.getString(1)
return user.email
proc createUser*(email: string, encodedHash: string) =
{.gcsafe.}:
db1.transaction:
discard db1.insert(InsertUser, email, encodedHash)