-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
分库分表:结果集处理——聚合函数(不含 Group By 子句) #187
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #187 +/- ##
==========================================
+ Coverage 84.86% 86.07% +1.20%
==========================================
Files 36 43 +7
Lines 2723 3045 +322
==========================================
+ Hits 2311 2621 +310
- Misses 335 343 +8
- Partials 77 81 +4
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
明日再看看
func TestColumnType(t *testing.T) {
db, err := sql.Open("mysql", "root:root@tcp(localhost:13306)/integration_test")
require.NoError(t, err)
defer func() {
db.Exec("DELETE FROM `order`")
db.Exec("DELETE FROM `item`")
db.Exec("DELETE FROM `order_detail`")
}()
o, err := eorm.Open("mysql", single.NewDB(db))
require.NoError(t, err)
initSql(o, t)
rows, err := db.Query("SELECT * FROM `order` limit 1")
require.NoError(t, err)
types, err := rows.ColumnTypes()
require.NoError(t, err)
var vals []any
for _, typ := range types {
goType := typ.ScanType()
zero := reflect.New(goType)
vals = append(vals, zero.Interface())
}
rows.Next()
err = rows.Scan(vals...)
require.NoError(t, err)
fmt.Println(vals)
} 确实可以拿到。但是我没有进一步考察,还要考虑一些数据库上奇怪的类型,尤其是 big int, big unsign int 之类的,在转为 Go 类型的时候会不会有问题。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我注意到一个问题,在除了 Avg 以外的所有的聚合函数都要求传入一个 alias,我看上去有点多余。比如说在 ColInfo 里面已经有了一个 name,那么在我的设想里面,这个 name 代表的就是我们的列名,即是数据库返回的列名,也是我们在 rows.Columns 里面使用的列名。
那么:
SELECT SUM(age) FROM
ColInfo.name 应该是 SUM(age)
而:
SELECT SUM(age) as sum_age FROM
这个 ColInfo.Name 就是 sum_age。
在结果集处理层面上,应该没有 alias 这个概念的。
@juniaoshaonian deepsource 有一个小问题,你修复一下。 |
OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark
@juniaoshaonian golangci-lint 问题修复一下 |
奇怪了我就改了个变量名呀,昨天还可以的 |
No description provided.