forked from mirrors/homebox
feat: chinese-currency (#158)
* run updated code gen * feat: add RMB currency support
This commit is contained in:
parent
e8f215ce34
commit
1dc1ee54e2
42 changed files with 565 additions and 1324 deletions
|
@ -548,6 +548,11 @@ func (iq *ItemQuery) Select(fields ...string) *ItemSelect {
|
|||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a ItemSelect configured with the given aggregations.
|
||||
func (iq *ItemQuery) Aggregate(fns ...AggregateFunc) *ItemSelect {
|
||||
return iq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (iq *ItemQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range iq.fields {
|
||||
if !item.ValidColumn(f) {
|
||||
|
@ -778,7 +783,7 @@ func (iq *ItemQuery) loadLabel(ctx context.Context, query *LabelQuery, nodes []*
|
|||
outValue := *values[0].(*uuid.UUID)
|
||||
inValue := *values[1].(*uuid.UUID)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*Item]struct{}{byID[outValue]: struct{}{}}
|
||||
nids[inValue] = map[*Item]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
|
@ -1043,8 +1048,6 @@ func (igb *ItemGroupBy) sqlQuery() *sql.Selector {
|
|||
for _, fn := range igb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(igb.fields)+len(igb.fns))
|
||||
for _, f := range igb.fields {
|
||||
|
@ -1064,6 +1067,12 @@ type ItemSelect struct {
|
|||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (is *ItemSelect) Aggregate(fns ...AggregateFunc) *ItemSelect {
|
||||
is.fns = append(is.fns, fns...)
|
||||
return is
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (is *ItemSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := is.prepareQuery(ctx); err != nil {
|
||||
|
@ -1074,6 +1083,16 @@ func (is *ItemSelect) Scan(ctx context.Context, v any) error {
|
|||
}
|
||||
|
||||
func (is *ItemSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(is.fns))
|
||||
for _, fn := range is.fns {
|
||||
aggregation = append(aggregation, fn(is.sql))
|
||||
}
|
||||
switch n := len(*is.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
is.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
is.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := is.sql.Query()
|
||||
if err := is.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue