Clojure 如何在korma中访问其他模式中的表?
在SQL中,访问其他模式中的表很简单:Clojure 如何在korma中访问其他模式中的表?,clojure,korma,sqlkorma,Clojure,Korma,Sqlkorma,在SQL中,访问其他模式中的表很简单: select * from other_schema.t where ... 在科尔马我怎么做?我实际上要做的是访问信息\u schema.tablestable。因此,通过defdb定义另一个db是没有帮助的 我试图定义实体,但是失败了 (defentity information_schema.tables) 您应该能够通过定义另一个db来实现这一点。我可以创建这样的db: 创建数据库my_db; 使用我的数据库; 创建表格材料( 瓦查尔(255
select *
from other_schema.t
where ...
在科尔马我怎么做?我实际上要做的是访问信息\u schema.tables
table。因此,通过defdb
定义另一个db
是没有帮助的
我试图定义实体,但是失败了
(defentity information_schema.tables)
您应该能够通过定义另一个db来实现这一点。我可以创建这样的db:
创建数据库my_db;
使用我的数据库;
创建表格材料(
瓦查尔(255)
);
插入物品(物品)价值(“某些物品”);
现在我定义了两个Korma数据库和实体,并查询它们:
(defdb my db(mysql{:host“localhost”)
:端口3306
:db“my_db”
:用户“root”
:密码nil})
(defdb信息模式(mysql{:host“localhost”)
:端口3306
:db“信息\模式”
:用户“root”
:密码nil})
(防御性材料)
(防御信息模式)
(挑选材料
(数据库我的数据库))
;; => ({:things“some things”})
(选择表格)
(数据库信息模式)
(字段:表\模式:表\名称)
(其中{:TABLE_SCHEMA“my_db”}))
;; => ({:TABLE_NAME“stuff”,:TABLE_SCHEMA“my_db”})
我必须知道,在定义实体时,有一种方法可以指定基表。指定基表时,它允许使用
设置模式
(defentity tables
(table :information_schema.tables))
这可以很好地访问
信息\u schema.tables
table,而无需定义另一个数据库。谢谢您回答我的问题。不幸的是,我不知道root
用户密码,所以我无法应用您的建议。无论如何,我找到了更合适的方法。请参考我自己的答案。您不需要root用户,每个用户都会看到他们有权访问的对象的信息\u模式的结果,但我不想通过添加GRANT语句来混淆示例