MCPcopy Index your code
hub / github.com/TruthHun/BookStack / FindToPager

Method FindToPager

models/book_result.go:126–167  ·  view source on GitHub ↗
(pageIndex, pageSize int, private int, wd ...string)

Source from the content-addressed store, hash-verified

124}
125
126func (m *BookResult) FindToPager(pageIndex, pageSize int, private int, wd ...string) (books []*BookResult, totalCount int, err error) {
127 var args []interface{}
128 word := ""
129 if len(wd) > 0 {
130 if w := strings.TrimSpace(wd[0]); w != "" {
131 word = w
132 }
133 }
134 o := orm.NewOrm()
135 q := o.QueryTable(NewBook().TableNameWithPrefix())
136 if word != "" {
137 cond := orm.NewCondition().Or("book_name__icontains", word).Or("description__icontains", word)
138 q = q.SetCond(orm.NewCondition().AndCond(cond))
139 }
140 q = q.Filter("privately_owned", private)
141
142 count, err := q.Count()
143 if err != nil {
144 return
145 }
146
147 totalCount = int(count)
148
149 sql := `SELECT
150 book.*,rel.relationship_id,rel.role_id,m.account AS create_name
151 FROM md_books AS book
152 LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.role_id = 0
153 LEFT JOIN md_members AS m ON rel.member_id = m.member_id %v
154 ORDER BY book.order_index DESC ,book.book_id DESC LIMIT ?,?`
155 condition := ""
156 condition = "where book.privately_owned=" + strconv.Itoa(private)
157 if word != "" {
158 condition = condition + " and (book.book_name like ? or book.description like ?)"
159 args = append(args, "%"+word+"%", "%"+word+"%")
160 }
161
162 sql = fmt.Sprintf(sql, condition)
163 offset := (pageIndex - 1) * pageSize
164 args = append(args, offset, pageSize)
165 _, err = o.Raw(sql, args...).QueryRows(&books)
166 return
167}

Callers

nothing calls this directly

Calls 4

NewBookFunction · 0.85
appendFunction · 0.50
TableNameWithPrefixMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected