admin管理员组文章数量:1125080
I'm developing a multi-tenant app using Rust (diesel as its DB driver) and PostgreSQL. I've decided to use Row Level Security in PostgreSQL to enforce data isolation in the DB layer rather than having to filter on tenant_id
in each query. This works well, as in my function to fetch a connection from the AsyncDbPool
I just set the right tenant context and don't need to worry about filtering in my queries.
However, as this is enforced in the DB, I'd very much like to abstract my Rust models from having to include tenant_id
in them. Is that somehow possible?
I've tried to use AsChangeset
to omit the tenant_id
from the struct definition:
#[derive(Queryable, Insertable, Serialize, Deserialize, AsChangeset)]
#[diesel(table_name = users)]
pub struct User {
pub id: Uuid,
pub email: String,
pub display_name: Option<String>,
}
but Rust still complains:
this is a mismatch between what your query returns and what your type expects the query to return
the fields in your struct need to match the fields returned by your query in count, order and type
I guess that's because AsChangeset
allows me to omit nullable fields from new item creation, but don't really work for filtering fields on selected items.
本文标签: Multitenant Rust dieselPostgreSQL without tenantid in each modelStack Overflow
版权声明:本文标题:Multi-tenant Rust diesel + PostgreSQL without tenant_id in each model - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736655033a1946231.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论