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

@ -440,6 +440,11 @@ func (lq *LocationQuery) Select(fields ...string) *LocationSelect {
return selbuild
}
// Aggregate returns a LocationSelect configured with the given aggregations.
func (lq *LocationQuery) Aggregate(fns ...AggregateFunc) *LocationSelect {
return lq.Select().Aggregate(fns...)
}
func (lq *LocationQuery) prepareQuery(ctx context.Context) error {
for _, f := range lq.fields {
if !location.ValidColumn(f) {
@ -794,8 +799,6 @@ func (lgb *LocationGroupBy) sqlQuery() *sql.Selector {
for _, fn := range lgb.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(lgb.fields)+len(lgb.fns))
for _, f := range lgb.fields {
@ -815,6 +818,12 @@ type LocationSelect struct {
sql *sql.Selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (ls *LocationSelect) Aggregate(fns ...AggregateFunc) *LocationSelect {
ls.fns = append(ls.fns, fns...)
return ls
}
// Scan applies the selector query and scans the result into the given value.
func (ls *LocationSelect) Scan(ctx context.Context, v any) error {
if err := ls.prepareQuery(ctx); err != nil {
@ -825,6 +834,16 @@ func (ls *LocationSelect) Scan(ctx context.Context, v any) error {
}
func (ls *LocationSelect) sqlScan(ctx context.Context, v any) error {
aggregation := make([]string, 0, len(ls.fns))
for _, fn := range ls.fns {
aggregation = append(aggregation, fn(ls.sql))
}
switch n := len(*ls.selector.flds); {
case n == 0 && len(aggregation) > 0:
ls.sql.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
ls.sql.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := ls.sql.Query()
if err := ls.driver.Query(ctx, query, args, rows); err != nil {