Written in Go
Enjoy TiDB as much as we love Go. We believe Go code is both easy and enjoyable to work with. Go makes us improve TiDB fast and makes it easy to dive into the codebase.
func executeLine(tx *sql.Tx, txnLine string) error {
if tidb.IsQuery(txnLine) {
rows, err := tx.Query(txnLine)
if err != nil {
return errors.Trace(err)
}
defer rows.Close()
cols, err := rows.Columns()
if err != nil {
return errors.Trace(err)
}
values := make([][]byte, len(cols))
scanArgs := make([]interface{}, len(values))
for i := range values {
scanArgs[i] = &values[i]
}
var datas [][]string
for rows.Next() {
err := rows.Scan(scanArgs...)
if err != nil {
return errors.Trace(err)
}
data := make([]string, len(cols))
for i, value := range values {
if value == nil {
data[i] = "NULL"
} else {
data[i] = string(value)
}
}
datas = append(datas, data)
}
// For `cols` and `datas[i]` always has the same length,
// no need to check return validity.
result, _ := printer.GetPrintResult(cols, datas)
fmt.Printf("%s", result)
if err := rows.Err(); err != nil {
return errors.Trace(err)
}
} else {
// TODO: rows affected and last insert id
_, err := tx.Exec(txnLine)
if err != nil {
return errors.Trace(err)
}
}
return nil
}
Literally the first file I opened.
Sorry, I do not get your point. Is there any problem with this file?
I just fail to see how this is enjoyable to work with. There's a lot of boilerplate for allocation, iteration, error handling every few lines. It's very verbose in general.
I started to write golang three month ago. At first I have the similar feeling with you. But now I think golang is an excellent programming language.
We DO NOT LIE because all of us really enjoy work with golang. I suggest you to work with golang for some time and then consider this issue again.
Thanks for your attention!
Instead of being a prick, try providing actionable feedback in the future. Go code tends to be verbose when working with database/sql. I think this is an interesting project, and I look forward to watching it progress.
Thank you for watching.
Most helpful comment
I started to write golang three month ago. At first I have the similar feeling with you. But now I think golang is an excellent programming language.
We DO NOT LIE because all of us really enjoy work with golang. I suggest you to work with golang for some time and then consider this issue again.
Thanks for your attention!