aboutsummaryrefslogtreecommitdiff
path: root/src/guff/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/guff/models')
-rw-r--r--src/guff/models/user.cr32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/guff/models/user.cr b/src/guff/models/user.cr
index a76fc61..bdbb0de 100644
--- a/src/guff/models/user.cr
+++ b/src/guff/models/user.cr
@@ -2,6 +2,23 @@ require "crypto/bcrypt"
class Guff::UserModel < Guff::Model
SQL = TemplateCache.new({
+ get_users: "
+ SELECT a.user_id,
+ a.created_at,
+ a.is_active,
+ a.user_name,
+ b.role_name,
+ c.email
+
+ FROM users a
+ JOIN roles b
+ ON (b.role_id = a.role_id)
+ JOIN user_logins c
+ ON (c.user_id = a.user_id)
+
+ ORDER BY LOWER(a.user_name)
+ ",
+
add_user: "
INSERT INTO users(user_name) VALUES (:user_name)
",
@@ -39,10 +56,17 @@ class Guff::UserModel < Guff::Model
end
def get_users
- r = [] of Hash(String, String)
-
- all(:get_users) do |row|
- r << row
+ r = [] of Hash(String, Int64 | String | Bool)
+
+ all(:get_users, nil, nil) do |row|
+ r << {
+ "user_id": row["user_id"] as Int64,
+ "created_at": row["created_at"] as String,
+ "is_active": ((row["is_active"] as Int64) == 1),
+ "user_name": row["user_name"] as String,
+ "role_name": row["role_name"] as String,
+ "email": row["email"] as String,
+ }
end
r