Make orderStr private
This commit is contained in:
parent
5fa0a473c7
commit
09156d1ecb
|
@ -12,19 +12,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (statement *Statement) HasOrderBy() bool {
|
func (statement *Statement) HasOrderBy() bool {
|
||||||
return statement.OrderStr != ""
|
return statement.orderStr != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetOrderBy reset ordery conditions
|
// ResetOrderBy reset ordery conditions
|
||||||
func (statement *Statement) ResetOrderBy() {
|
func (statement *Statement) ResetOrderBy() {
|
||||||
statement.OrderStr = ""
|
statement.orderStr = ""
|
||||||
statement.orderArgs = nil
|
statement.orderArgs = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteOrderBy write order by to writer
|
// WriteOrderBy write order by to writer
|
||||||
func (statement *Statement) WriteOrderBy(w builder.Writer) error {
|
func (statement *Statement) WriteOrderBy(w builder.Writer) error {
|
||||||
if len(statement.OrderStr) > 0 {
|
if len(statement.orderStr) > 0 {
|
||||||
if _, err := fmt.Fprintf(w, " ORDER BY %s", statement.OrderStr); err != nil {
|
if _, err := fmt.Fprintf(w, " ORDER BY %s", statement.orderStr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.Append(statement.orderArgs...)
|
w.Append(statement.orderArgs...)
|
||||||
|
@ -34,10 +34,10 @@ func (statement *Statement) WriteOrderBy(w builder.Writer) error {
|
||||||
|
|
||||||
// OrderBy generate "Order By order" statement
|
// OrderBy generate "Order By order" statement
|
||||||
func (statement *Statement) OrderBy(order string, args ...interface{}) *Statement {
|
func (statement *Statement) OrderBy(order string, args ...interface{}) *Statement {
|
||||||
if len(statement.OrderStr) > 0 {
|
if len(statement.orderStr) > 0 {
|
||||||
statement.OrderStr += ", "
|
statement.orderStr += ", "
|
||||||
}
|
}
|
||||||
statement.OrderStr += statement.ReplaceQuote(order)
|
statement.orderStr += statement.ReplaceQuote(order)
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
statement.orderArgs = append(statement.orderArgs, args...)
|
statement.orderArgs = append(statement.orderArgs, args...)
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,8 @@ func (statement *Statement) OrderBy(order string, args ...interface{}) *Statemen
|
||||||
// Desc generate `ORDER BY xx DESC`
|
// Desc generate `ORDER BY xx DESC`
|
||||||
func (statement *Statement) Desc(colNames ...string) *Statement {
|
func (statement *Statement) Desc(colNames ...string) *Statement {
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
if len(statement.OrderStr) > 0 {
|
if len(statement.orderStr) > 0 {
|
||||||
fmt.Fprint(&buf, statement.OrderStr, ", ")
|
fmt.Fprint(&buf, statement.orderStr, ", ")
|
||||||
}
|
}
|
||||||
for i, col := range colNames {
|
for i, col := range colNames {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
|
@ -57,15 +57,15 @@ func (statement *Statement) Desc(colNames ...string) *Statement {
|
||||||
_ = statement.dialect.Quoter().QuoteTo(&buf, col)
|
_ = statement.dialect.Quoter().QuoteTo(&buf, col)
|
||||||
fmt.Fprint(&buf, " DESC")
|
fmt.Fprint(&buf, " DESC")
|
||||||
}
|
}
|
||||||
statement.OrderStr = buf.String()
|
statement.orderStr = buf.String()
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asc provide asc order by query condition, the input parameters are columns.
|
// Asc provide asc order by query condition, the input parameters are columns.
|
||||||
func (statement *Statement) Asc(colNames ...string) *Statement {
|
func (statement *Statement) Asc(colNames ...string) *Statement {
|
||||||
var buf strings.Builder
|
var buf strings.Builder
|
||||||
if len(statement.OrderStr) > 0 {
|
if len(statement.orderStr) > 0 {
|
||||||
fmt.Fprint(&buf, statement.OrderStr, ", ")
|
fmt.Fprint(&buf, statement.orderStr, ", ")
|
||||||
}
|
}
|
||||||
for i, col := range colNames {
|
for i, col := range colNames {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
|
@ -74,6 +74,6 @@ func (statement *Statement) Asc(colNames ...string) *Statement {
|
||||||
_ = statement.dialect.Quoter().QuoteTo(&buf, col)
|
_ = statement.dialect.Quoter().QuoteTo(&buf, col)
|
||||||
fmt.Fprint(&buf, " ASC")
|
fmt.Fprint(&buf, " ASC")
|
||||||
}
|
}
|
||||||
statement.OrderStr = buf.String()
|
statement.orderStr = buf.String()
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ type Statement struct {
|
||||||
Start int
|
Start int
|
||||||
LimitN *int
|
LimitN *int
|
||||||
idParam schemas.PK
|
idParam schemas.PK
|
||||||
OrderStr string
|
orderStr string
|
||||||
orderArgs []interface{}
|
orderArgs []interface{}
|
||||||
JoinStr string
|
JoinStr string
|
||||||
joinArgs []interface{}
|
joinArgs []interface{}
|
||||||
|
|
Loading…
Reference in New Issue