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

sharding plugin seems not compatable with gorm.Model well. #14

Closed
redochenzhen opened this issue Mar 19, 2022 · 1 comment
Closed

sharding plugin seems not compatable with gorm.Model well. #14

redochenzhen opened this issue Mar 19, 2022 · 1 comment
Assignees

Comments

@redochenzhen
Copy link

my code works well befor using sharding middleware:

func (r *MySQLRepo) PlanExists(id uint) (bool, error) {
    var exists bool
    err := r.db.Model(&entity.StockPlan{}).
        Select("count(*) > 0").
        Where("id = ?", id).
        Find(&exists).
        Error
    return exists, err
}

but the error occurs after registering sharding like this:

db.Use(sharding.Register(sharding.Config{
    ShardingKey:         "title",
    NumberOfShards:      4,
    PrimaryKeyGenerator: sharding.PKSnowflake,
}, "stock_plans"))

and the error is:

Error 1054: Unknown column 'stock_plans.deleted_at' in 'where clause'

@hyperphoton
Copy link
Collaborator

var exists bool
err := db.Model(&Order{}).
	Select("count(*) > 0").
	Where("id = ?", int64(10)).
	Find(&exists).
	Error
assert.Equal(t, nil, err)

Above code can not get the error, can you provide more information?

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

3 participants