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

Why restrict the primary key of sharding to int64 and must be called "ID" #118

Open
DuskDrum opened this issue Jul 12, 2023 · 3 comments
Open
Assignees

Comments

@DuskDrum
Copy link

Why restrict the primary key of sharding to int64 and must be called "ID"

I am using the latest version 0.5.3 of gorm sharding and have encountered two issues with primary keys.
Problem 1: When inserting, a primary key will be generated based on the suffix. My suffix is not a number, which causes the insert to fail (such as line 363 of the sharding.go source code image). The solution comes from rows 357 and 358, but my table primary key is not called "ID" but "order_id". Is there a way to skip the error of row 363.
image

Question 2: When querying, if there is an "id" field, it must be of type int64, otherwise it will cause an error in line 486. Is there a way to skip this judgment and successfully query
image

Expected answer

I want to know if there is a way to bypass the limitation of gorm sharing for primary keys that are "ID" and of type int64

@cachalots
Copy link

I solved this by renaming the primary key column name to id, it's just needs you to have the id column and doesn't care if it's of type int. I don't understand why there must be an id column instead of customizing this column name.

@egandro
Copy link

egandro commented Sep 7, 2023

Same question - why not allow UUIDs?

It can be modul'ed 32,64,128... and can then create orders_0 ... orders_127

@luyongjuan

This comment was marked as abuse.

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

No branches or pull requests

5 participants