有没有一个支持PostgreSQL多个模式的Golang ORM库?

huangapple go评论114阅读模式
英文:

Is there an ORM library for Golang that support multiple schemas of Postgresql?

问题

我正在寻找一个适用于Golang的ORM库,可以支持与多个Postgresql模式一起使用。

这个想法是为了支持使用Postgres模式进行多租户(即在每个请求之前,检查应查询哪个租户,并在查询之前动态设置模式)。

有人熟悉这样的库吗?

英文:

I'm looking for an ORM library for Golang that supports working with multiple Postgresql schemas.

The idea is to support multi-tenancy using Postgres schemas. (i.e. upon each request, check which tenant should be queried and dynamically set the schema before querying)

Is anyone familiar with such a library?

答案1

得分: 2

请注意,到目前为止,我只使用了标准库,因此我对ORM与database/sql包的行为类似的假设可能是错误的。

我相信任何一个暴露类似于标准库的接口的ORM,比如xormgorm,应该能够通过设置search_path来实现在不同模式之间切换。

db.Exec("SET search_path TO tenant_schema_123")

这将为数据库句柄设置模式,使用该数据库句柄进行的任何后续查询都将发送到tenant_schema_123

英文:

Please note that I've only used the standard library so far and therefore my assumption that an ORM will behave in the same manner as the database/sql package might very well be wrong.


I believe any ORM that exposes an interface analogous to the standard one that allows you to execute plain sql statements, like xorm and gorm for example do, should be able to facilitate switching between schemas by setting the search_path.

db.Exec("SET search_path TO tenant_schema_123")

This sets the schema for the db handle and any successive queries using that db handle are made to tenant_schema_123.

huangapple
  • 本文由 发表于 2017年5月18日 21:28:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/44049133.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定