feat: chinese-currency (#158)

* run updated code gen

* feat: add RMB currency support
This commit is contained in:
Hayden 2022-12-01 16:45:28 -09:00 committed by GitHub
parent e8f215ce34
commit 1dc1ee54e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 565 additions and 1324 deletions

View file

@ -370,6 +370,11 @@ func (uq *UserQuery) Select(fields ...string) *UserSelect {
return selbuild
}
// Aggregate returns a UserSelect configured with the given aggregations.
func (uq *UserQuery) Aggregate(fns ...AggregateFunc) *UserSelect {
return uq.Select().Aggregate(fns...)
}
func (uq *UserQuery) prepareQuery(ctx context.Context) error {
for _, f := range uq.fields {
if !user.ValidColumn(f) {
@ -649,8 +654,6 @@ func (ugb *UserGroupBy) sqlQuery() *sql.Selector {
for _, fn := range ugb.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(ugb.fields)+len(ugb.fns))
for _, f := range ugb.fields {
@ -670,6 +673,12 @@ type UserSelect struct {
sql *sql.Selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (us *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect {
us.fns = append(us.fns, fns...)
return us
}
// Scan applies the selector query and scans the result into the given value.
func (us *UserSelect) Scan(ctx context.Context, v any) error {
if err := us.prepareQuery(ctx); err != nil {
@ -680,6 +689,16 @@ func (us *UserSelect) Scan(ctx context.Context, v any) error {
}
func (us *UserSelect) sqlScan(ctx context.Context, v any) error {
aggregation := make([]string, 0, len(us.fns))
for _, fn := range us.fns {
aggregation = append(aggregation, fn(us.sql))
}
switch n := len(*us.selector.flds); {
case n == 0 && len(aggregation) > 0:
us.sql.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
us.sql.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := us.sql.Query()
if err := us.driver.Query(ctx, query, args, rows); err != nil {