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

使用 gorm_gen 生成代码,如何进行列值运算 #1238

Open
QingsiLiu opened this issue Nov 26, 2024 · 0 comments
Open

使用 gorm_gen 生成代码,如何进行列值运算 #1238

QingsiLiu opened this issue Nov 26, 2024 · 0 comments

Comments

@QingsiLiu
Copy link

QingsiLiu commented Nov 26, 2024

您好!我使用 gorm 生成了对应表结构的代码,在使用where 条件进行查询时,如何正确使用 Add 等方法?
例如这样一段 sql

         SELECT
		lco.id,
		lco.arranging_time,
		lco.name
	FROM
		 lco
	WHERE
		lco.user_id = ? 
		AND lco.arranging_time + lco.course_duration * 60 + 60 * ? >= ? 
		AND lco.arranging_time <= ? 
		AND lco.status = `2;

golang 代码:

err = lco.WithContext(h.Context).Select(lco.ID, lco.ArrangingTime, lco.Name).
		Where(lco.ArrangingTime.Add(lco.CourseDuration.Mul(60).Add(int32(signinTimeLimitH*60))).Gte(int32(now))).
		Where(lco.ArrangingTime.Lte(int32(now))).
		Where(lco.Status.Eq(2), lco.UserID.Eq(userInfoId)).
		Scan(&result)

会遇到报错:cannot use lco.CourseDuration.Mul(60).Add(int32(signinTimeLimitH * 60)) (value of type field.Int32) as int32 value in argument to lco.ArrangingTime.Add

这样的问题要如何解决?最佳实践是什么

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

1 participant