ecodeclub / eorm

简单 ORM 框架
Apache License 2.0
194 stars 64 forks source link

Aggregate functions #12

Closed flycash closed 3 years ago

flycash commented 3 years ago

English Only

Please check existing issues first to avoid duplication and answer the questions below before submitting your issue.

Use case(s)

We need to support major aggregate functions, check MySQL aggregate functions

We only support a few of them. (Please state use cases, what problem will this feature solve?)

Proposed Solution

Here is an example:

// As specifies the alias
func (Aggregate) As(alias string) Aggregate {
    panic("implement me")
}

// Avg represents AVG
func Avg(c string) Aggregate {
    panic("implement")
}

You need to think about this:

New().Select(Columns("Id"), Avg("Age").As("avg_age")).From(&TestModel{}) //  "SELECT `id`, AVG(`age`) as `avg_age` FROM `test_model`;",

(Please describe your proposed design/solution, if any)

Alternatives Considered

(Other possible options for solving the problem?)

Additional Context

It relies on #10

(Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's very hard to read otherwise.)

(If you can, link to the line of code that might be helpful to explain the context)