完善
This commit is contained in:
parent
c70bcf5895
commit
84f24945ee
|
@ -183,10 +183,15 @@ func (w SqlBuilder) parseJoin() string {
|
||||||
|
|
||||||
func SimplePagination[T Model](where ParseWhere, fields, group string, page, pageSize int, order SqlBuilder, join SqlBuilder, having SqlBuilder, in ...[]any) (r []T, total int, err error) {
|
func SimplePagination[T Model](where ParseWhere, fields, group string, page, pageSize int, order SqlBuilder, join SqlBuilder, having SqlBuilder, in ...[]any) (r []T, total int, err error) {
|
||||||
var rr T
|
var rr T
|
||||||
w, args, err := where.ParseWhere(&in)
|
var w string
|
||||||
if err != nil {
|
var args []any
|
||||||
return r, total, err
|
if where != nil {
|
||||||
|
w, args, err = where.ParseWhere(&in)
|
||||||
|
if err != nil {
|
||||||
|
return r, total, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h := ""
|
h := ""
|
||||||
if having != nil {
|
if having != nil {
|
||||||
hh, arg, err := having.ParseWhere(&in)
|
hh, arg, err := having.ParseWhere(&in)
|
||||||
|
@ -266,9 +271,14 @@ func FindOneById[T Model, I helper.IntNumber](id I) (T, error) {
|
||||||
|
|
||||||
func FirstOne[T Model](where ParseWhere, fields string, order SqlBuilder, in ...[]any) (T, error) {
|
func FirstOne[T Model](where ParseWhere, fields string, order SqlBuilder, in ...[]any) (T, error) {
|
||||||
var r T
|
var r T
|
||||||
w, args, err := where.ParseWhere(&in)
|
var w string
|
||||||
if err != nil {
|
var args []any
|
||||||
return r, err
|
var err error
|
||||||
|
if where != nil {
|
||||||
|
w, args, err = where.ParseWhere(&in)
|
||||||
|
if err != nil {
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tp := "select %s from %s %s %s"
|
tp := "select %s from %s %s %s"
|
||||||
sql := fmt.Sprintf(tp, fields, r.Table(), w, order.parseOrderBy())
|
sql := fmt.Sprintf(tp, fields, r.Table(), w, order.parseOrderBy())
|
||||||
|
@ -281,9 +291,14 @@ func FirstOne[T Model](where ParseWhere, fields string, order SqlBuilder, in ...
|
||||||
|
|
||||||
func LastOne[T Model](where ParseWhere, fields string, in ...[]any) (T, error) {
|
func LastOne[T Model](where ParseWhere, fields string, in ...[]any) (T, error) {
|
||||||
var r T
|
var r T
|
||||||
w, args, err := where.ParseWhere(&in)
|
var w string
|
||||||
if err != nil {
|
var args []any
|
||||||
return r, err
|
var err error
|
||||||
|
if where != nil {
|
||||||
|
w, args, err = where.ParseWhere(&in)
|
||||||
|
if err != nil {
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tp := "select %s from %s %s order by %s desc limit 1"
|
tp := "select %s from %s %s order by %s desc limit 1"
|
||||||
sql := fmt.Sprintf(tp, fields, r.Table(), w, r.PrimaryKey())
|
sql := fmt.Sprintf(tp, fields, r.Table(), w, r.PrimaryKey())
|
||||||
|
@ -298,7 +313,7 @@ func SimpleFind[T Model](where ParseWhere, fields string, in ...[]any) ([]T, err
|
||||||
var r []T
|
var r []T
|
||||||
var rr T
|
var rr T
|
||||||
var err error
|
var err error
|
||||||
args := make([]any, 0, 0)
|
var args []any
|
||||||
var w string
|
var w string
|
||||||
if where != nil {
|
if where != nil {
|
||||||
w, args, err = where.ParseWhere(&in)
|
w, args, err = where.ParseWhere(&in)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user