diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-04-01 21:47:36 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-04-01 21:47:36 -0400 |
commit | dc03d9202dae2a44af2410d68b2e35d500a8a5ac (patch) | |
tree | cdcd92b58f9f997302c83a7c5c77e1e35de39a3e /src/guff/models | |
parent | 0e91a6b3ad2feb7718d6ffdfb06660451f5d064e (diff) | |
download | old-guff-dc03d9202dae2a44af2410d68b2e35d500a8a5ac.tar.bz2 old-guff-dc03d9202dae2a44af2410d68b2e35d500a8a5ac.zip |
add get_users
Diffstat (limited to 'src/guff/models')
-rw-r--r-- | src/guff/models/user.cr | 32 |
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 |