func (p *Scope) PageJson2(lst T, pf *filter.PageFilter) *db.Paging { p.checkModel(lst) if pf != nil { p.builder.Limit(pf.PerPage(), pf.Skip()) visitor := filter.Visitor{} visitor.Quote = p.orm.dialect.Quote sa := visitor.Visitor(pf.Group) p.builder.Where(sa.Sql, sa.Args...) } var rows *sql.Rows paging := &db.Paging{} paging.Total = p.Count(lst) if !p.builder.hasSelect() { p.builder.Select(`"Json"`) } sa := p.builder.SqlSelect() resultv := reflect.ValueOf(lst) if resultv.Kind() != reflect.Ptr || resultv.Elem().Kind() != reflect.Slice { panic("out argument must be a slice address") } slicev := resultv.Elem() if rows, p.Err = p._query2(sa); p.NotErr() { defer rows.Close() for rows.Next() { var v []byte rows.Scan(&v) obj := reflect.New(p.model.Type).Interface() json.Unmarshal(v, obj) slicev = reflect.Append(slicev, reflect.ValueOf(obj).Elem()) } resultv.Elem().Set(slicev.Slice(0, slicev.Len())) } paging.Items = lst return paging }
func (p *Scope) Page2(model T, pf *filter.PageFilter) *db.Paging { p.checkModel(model) if pf != nil { p.builder.Limit(pf.PerPage(), pf.Skip()) visitor := filter.Visitor{} visitor.Quote = p.orm.dialect.Quote sa := visitor.Visitor(pf.Group) p.builder.Where(sa.Sql, sa.Args...) } var rows *sql.Rows paging := &db.Paging{} paging.Total = p.Count(model) sa := p.builder.SqlSelect() if rows, p.Err = p._query2(sa); p.NotErr() { defer rows.Close() p.model.MapRowsAsLst(rows, model) paging.Items = model } return paging }
func (p *Scope) buildWhere() (sa db.SqlArgs) { if !p.haswhere { return } else if p.whereid != nil { sa.Sql = fmt.Sprintf(" WHERE (%v=?)", p.quote(p.model.Id())) sa.AddArgs(p.whereid) } else if len(p.wheresql) > 0 { sa.Sql = " WHERE " + p.wheresql sa.AddArgs(p.whereargs...) } else if p.pf != nil { visitor := filter.Visitor{} visitor.Quote = p.orm.dialect.Quote sa = visitor.Visitor(p.pf.Group) if sa.Sql != "" { sa.Sql = " WHERE " + sa.Sql } return } else if len(p.where) > 0 { } return }