有没有办法制作一个不使用持久ID机制的表键?

发布于 2025-01-08 12:40:02 字数 242 浏览 2 评论 0原文

我正在尝试在 yesod 中设置我的 postgres 架构。计划是让 yesod 生成表,但我将通过 C++ 程序中的 lua 脚本将新记录插入到表中。我希望其中一个表有一个基于来自 C++ 环境的唯一 Int64 的主键。我可以持久化将此列视为表键,但不自动生成 id 吗?

我想我也可以有一个常规的持久样式记录 ID 列和一个 Int64 列,但这似乎很浪费而且过于复杂。 Int64 将始终是唯一的,我将使用它来查找表记录以查看它们是否已经存在。

I'm trying to set up my postgres schema in yesod. The plan is to let yesod generate the tables, but I'll be inserting new records into the tables from a lua script in a C++ program. I'd like one of the tables to have a primary key based on a unique Int64 that comes from the C++ environment. Can I get Persistent to treat this column as the table key, but without the automatic id generation?

I guess I could have a regular persistent-style record ID column and an Int64 column too but that seems wasteful and overly complicated. The Int64 will always be unique and that's what I'll use to do lookups on the table records to see if they exist already.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉目亦如画i 2025-01-15 12:40:02

我认为这个问题是在邮件列表上提出的。简短的回答是否定的,持久化中的主键是自增的,但是你可以有二级索引

I think this question was asked on the mail list. The short answer is no, the primary key in Persistent is auto-increment, but you can have secondary indexes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文