This commit is contained in:
2024-07-01 02:43:57 +05:30
parent 6f5fae7d74
commit 11a81f098f

39
src/services.v Normal file
View File

@@ -0,0 +1,39 @@
module main
import databases
fn (mut app App) service_add_user(username string, email string, password string) ! {
mut db := databases.create_db_connection()!
defer {
db.close() or { panic(err) }
}
print(1)
results := sql db {
select from Auth where username == username && email == email
}!
if results.len > 0 {
return error('User already exists')
}
auth_model := Auth{
username: username,
email: email,
password: password,
access_level: 1,
}
mut insert_error := ''
sql db {
insert auth_model into Auth
} or { insert_error = err.msg() }
if insert_error != '' {
return error(insert_error)
}
}