如何列出所有用户创建的属性?

编程入门 行业动态 更新时间:2024-10-27 02:17:19
本文介绍了如何列出所有用户创建的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图找到所有用户创建的属性与下面的代码,它返回许多其他默认属性,如 db / unique 和 fressian /标签。

我想得到一个没有他们的集合,所以我想知道是否有一个更好的方式来获得它比过滤出属性的前缀。 p>

感谢

(q {:find'[?ident] :where'[[:db.part / db:db.install / attribute?p] [?p:db / ident?ident]]} db)

datomic.db.Attribute)(:elements(p / db)))

解决方案

一种方法是白/黑列出要过滤或包含的命名空间。请注意,一些Datomic的内置属性和用户属性之间没有差别。您可以在任何系统命名空间中自由创建属性,例如 db.type 但是当然你不应该这样做。

说到这里,只有几个命名空间用于系统属性,所以你可以简单地过滤掉这些已知的命名空间。例如

(def system-ns#{dbdb.typedb.installdb.part db.langfressiandb.uniquedb.excisedb.cardinalitydb.fn}) '[:find?e?ident :in $?system-ns :其中 [?e:db / ident?ident] [(namespace?ident)? ns] [((comp不包含?)?system-ns?ns]]] (d / db conn)system-ns) pre>

I tried to find all user-created attributes with the code below and it returns many other default attributes, like db/unique and fressian/tag.

I'd like to get a set without them, so I was wondering if there is a better way to get it than filtering out the attributes by their prefixes.

Thanks

(q {:find '[?ident] :where '[[:db.part/db :db.install/attribute ?p] [?p :db/ident ?ident]]} db)

or

(filter (partial instance? datomic.db.Attribute) (:elements (p/db)))

解决方案

One way to do it is to white/black list the namespaces you want to filter out or include. Note there's no difference between some of Datomic's built-in attributes and user attributes. You can freely create attributes in any of the system namespaces e.g. db.type but of course you're not supposed to do it.

Having said that, there's only a few namespaces used for system attributes so you could simply filter out those known namespaces. e.g.

(def system-ns #{"db" "db.type" "db.install" "db.part" "db.lang" "fressian" "db.unique" "db.excise" "db.cardinality" "db.fn"}) (d/q '[:find ?e ?ident :in $ ?system-ns :where [?e :db/ident ?ident] [(namespace ?ident) ?ns] [((comp not contains?) ?system-ns ?ns)]] (d/db conn) system-ns)

更多推荐

如何列出所有用户创建的属性?

本文发布于:2023-10-21 17:38:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1514906.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!