Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果系统中的表是分库的,这样能支持吗? #313

Open
bigfacewo opened this issue Sep 20, 2021 · 4 comments
Open

如果系统中的表是分库的,这样能支持吗? #313

bigfacewo opened this issue Sep 20, 2021 · 4 comments
Labels

Comments

@bigfacewo
Copy link

假如我现在有两张表,usergroupgroup有一个字段owner_id关联到user表的id,但是这两张表是在两个数据库中的,这时候我还能使用APIJSON吗?
我希望在查询group列表的时候,会自动给每一个对象加一个字段owner,就是当前group关联的user对象的信息。
我该怎么做呢?

@bigfacewo
Copy link
Author

或者我应该说得详细一点,就是说我目前用户单独起了一个服务在管理user-center,组也是一个单独的服务group-center,组用到用户的信息都是去user-center取的,假如说APIJSON能够从另外一个APIJSON服务拿数据那就太棒了。

@bigfacewo
Copy link
Author

bigfacewo commented Sep 20, 2021

另外还有个区别就是,我去user-center拿数据是批量拿回来,再合并到组的数据里面的,主要是考虑效率问题,如果APIJSON也能考虑这种情况就更好了。

@TommyLemon
Copy link
Collaborator

TommyLemon commented Sep 23, 2021

可以通过 @datasource/@database/@Schema 指定不同数据源来支持。
image

{
    "@datasource": "DRUID",
    "User": {
        "id": 82001,
        "@datasource": "HIKARICP",
        "@database": "POSTGRESQL"
    },
    "[]": {
        "Comment": {
            "userId@": "User/id"
        },
        "Moment": {
            "@datasource": "DRUID",
            "id@": "/Comment/momentId"
        }
    },
    "@explain": true
}

“自动给每一个对象加一个字段owner” 前端在参数 group 对象里传参 owner 对象引用赋值就行了。

image

{
    "[]": {
        "Comment": {
            "User": {
                "id@": "/userId",
                "@column": "id,name"
            }
        }
    }
}

image

{
    "Comment[]": {
        "Comment": {
            "User": {
                "id@": "/userId",
                "@column": "id,name"
            }
        }
    }
}

image

{
    "[]": {
        "Comment": {},
        "User": {
            "id@": "/Comment/userId",
            "@column": "id,name"
        }
    }
}

http://apijson.cn/api/

@TommyLemon
Copy link
Collaborator

另外还有个区别就是,我去user-center拿数据是批量拿回来,再合并到组的数据里面的,主要是考虑效率问题,如果APIJSON也能考虑这种情况就更好了。

用 APP JOIN
image

image

https://github.com/Tencent/APIJSON/blob/master/Document.md#3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants