有没有办法制作一个不使用持久ID机制的表键?
我正在尝试在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这个问题是在邮件列表上提出的。简短的回答是否定的,持久化中的主键是自增的,但是你可以有二级索引
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