0

在 SQL 中,访问其他模式中的表很简单:

select * 
from other_schema.t
where ...

我怎么能在科尔马做到这一点?我实际上要做的是访问information_schema.tables表。db所以定义另一个defdb不会有帮助。

我试图定义实体,但是失败了。

(defentity information_schema.tables)
4

2 回答 2

2

我必须知道在定义实体时有一种方法可以指定基表。指定基表时,它允许使用..

(defentity tables
  (table :information_schema.tables))

这适用于访问information_schema.tables表,而无需定义另一个数据库。

于 2014-11-14T05:40:01.653 回答
0

您应该能够通过定义另一个数据库来做到这一点。我可以像这样创建一个数据库:

CREATE database my_db;
USE my_db;
CREATE TABLE stuff (
  things VARCHAR(255)
);
INSERT INTO stuff (things) VALUES ("some things");

现在我定义了两个 Korma 数据库和实体,并查询它们:

(defdb my-db (mysql {:host "localhost" 
                     :port 3306 
                     :db "my_db"
                     :user "root"
                     :password nil}))

(defdb information-schema (mysql {:host "localhost" 
                                  :port 3306 
                                  :db "information_schema" 
                                  :user "root" 
                                  :password nil}))


(defentity stuff)

(defentity information-schema)

(select stuff
        (database my-db))

;; => ({:things "some things"})

(select TABLES 
        (database information-schema) 
        (fields :TABLE_SCHEMA :TABLE_NAME) 
        (where {:TABLE_SCHEMA "my_db"}))

;; => ({:TABLE_NAME "stuff", :TABLE_SCHEMA "my_db"})
于 2014-11-12T16:54:11.240 回答