Replies: 6 comments
-
Hi @sswanv . Yes, you can reuse the statement. According to your example, the only difference is the projections: var projectionList ProjectionList
if isCount {
projectionList = ProjectionList{COUNT(User.UserID)}
} else {
projectionList = ProjectionList{User.AllColumns, UserInvite.AllColumns}
}
queryStmt := SELECT(projectionList).
FROM(UserInvite.INNER_JOIN(User, User.UserID.EQ(UserInvite.UserID))).
WHERE(UserInvite.InviteUserID.EQ(Int64(9527))) The same applies for |
Beta Was this translation helpful? Give feedback.
-
Thank you for helping ! |
Beta Was this translation helpful? Give feedback.
-
Hi, @go-jet, there is one more question. func (a *UserInviteAction) GetFiled(name string) Column {
for _, column := range User.AllColumns {
if column.Name() == name {
return column
}
}
return nil
}
func (a *UserInviteAction) GetInviteUser(ctx context.Context, db qrm.DB, searchInfo *search.SearchInfo, userID int64, isAdminUser bool) {
var sortInfo struct {
Sort string
Order string
}
var pageInfo struct {
Page int64
PageSize int64
}
queryStmt := UserPool.SELECT(userInviteExpectAutoSetColumns).
FROM(UserInvite.INNER_JOIN(User, User.UserID.EQ(UserInvite.UserID))).
WHERE(UserInvite.Depth.EQ(Int64(1)))
column := a.GetFiled(sortInfo.Sort)
if column != nil {
if sortInfo.Order == "DESC" {
queryStmt = queryStmt.ORDER_BY(column.DESC())
} else {
queryStmt = queryStmt.ORDER_BY(column.ASC())
}
}
queryStmt.OFFSET(pageInfo.Page * pageInfo.PageSize).LIMIT(pageInfo.PageSize)
// TODO There is also a query for the total number of items based on conditions,
// which is actually the demand for paging query. I don’t know how to write it well.
} |
Beta Was this translation helpful? Give feedback.
-
You can retrieve total number of items in single query. There are couple of ways. One way is to use var userInviteExpectAutoSetColumns ProjectionList
// construct projection list
var orderBy OrderByClause
// construct orderBy
queryStmt := SELECT(
userInviteExpectAutoSetColumns,
COUNT(STAR).OVER().AS("total_count"),
).
FROM(
UserInvite.
INNER_JOIN(User, User.UserID.EQ(UserInvite.UserID)),
).
WHERE(UserInvite.Depth.EQ(Int64(1))).
ORDER_BY(orderBy).
OFFSET(pageInfo.Page * pageInfo.PageSize).
LIMIT(pageInfo.PageSize);
var dest struct {
model.User // guess
Invites []model.UserInvite // guess
TotalCount int64
}
err := queryStmt.QueryContext(ctx, db, &dest) |
Beta Was this translation helpful? Give feedback.
-
What is the best way to pass the orderby parameter through http body, because the column of jet is formulated in the form of variables, I am a little confused, I hope your reply ! |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hello, now there is a need for paging, you need to find out the data and total number of the corresponding page, and whether the conditional statement can be reused, example:
Beta Was this translation helpful? Give feedback.
All reactions