Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SQL数据库中存储和检索朋友角色?_Sql_Clojure_Authorization - Fatal编程技术网

如何在SQL数据库中存储和检索朋友角色?

如何在SQL数据库中存储和检索朋友角色?,sql,clojure,authorization,Sql,Clojure,Authorization,我不知道如何在数据库中存储Friend角色。我可以存储字符串“#{::user}”,也可以存储“user”并在检索时对其进行转换。前者是糟糕的绝句,我不知道如何在不让天使哭泣的情况下做后者 (ns foo.handler (:require [cemerick.friend :as friend] (cemerick.friend [workflows :as workflows] [credentials :as creds

我不知道如何在数据库中存储
Friend
角色。我可以存储字符串
“#{::user}”
,也可以存储
“user”
并在检索时对其进行转换。前者是糟糕的绝句,我不知道如何在不让天使哭泣的情况下做后者

(ns foo.handler
  (:require [cemerick.friend :as friend]
        (cemerick.friend [workflows :as workflows]
                         [credentials :as creds])))

;; A dummy in-memory user "database"
(def users {"root" {:username "root"
                    :password (creds/hash-bcrypt "admin")
                    :roles #{::admin}}
            "jane" {:username "jane"
                    :password (creds/hash-bcrypt "pw")
                    :roles #{::user}}})

(derive ::admin ::user)

这就是我目前的做法;我敢肯定这一切都很糟糕。有人请阻止我。从数据库中提取的
“user”
开始:

foo.handler> #{(keyword (str *ns* "/" "user"))}
=> #{:foo.handler/user}

这是可行的,但为了更好地处理错误和清晰起见,您可以定义一个从数据库中存储的字符串到好友应用中角色的映射。像这样{“user”:foo.handler/user“admin”:foo.handler/admin…}并使用它为字符串获取正确的角色。