Skip to content

SECTION-073 リスト18.14のinterface{}ってanyとどう使い分けているのでしょうか? #72

Answered by budougumi0617
nnabeyang asked this question in Q&A
Discussion options

You must be logged in to vote

ご質問ありがとうございます。鋭い指摘ですね…!

repository.goanyinterface{} の使い分けは標準パッケージ由来のシグネチャか、 github.com/jmoiron/sqlx パッケージ由来のシグネチャかによって変わっています。
他のシーンでも適用できる一般化できるルールに則っているわけではなかったりします。

ExecContext などは標準パッケージの定義なのでany対応されてシグネチャが宣言されています。
https://pkg.go.dev/database/sql#DB.ExecContext
対して、 SelectContext などのsqlx特有のものは大元が interface{} のままなのでsqlxに合わせて interface{} にしてあるといった感じです。
https://pkg.go.dev/github.com/jmoiron/sqlx#DB.SelectContext

(といいつつ今見るとsqlxにしかないQueryxContextでも any になっていたりしますね 🙇

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nnabeyang
Comment options

Answer selected by nnabeyang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
errata 書籍の誤字・脱字・誤りの指摘 feedbacked サンプルコードや正誤表に反映済みのDiscussions
2 participants