-
Notifications
You must be signed in to change notification settings - Fork 1
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
goquの導入 #899
goquの導入 #899
Conversation
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.
goquの構文はよさそう
query := "SELECT * FROM sponsors WHERE id = " + id | ||
dialect := goqu.Dialect("mysql") | ||
query, _, err := dialect.From("sponsors").Where(goqu.Ex{"id": id}).ToSQL() | ||
fmt.Println(query) |
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.
fmt.Println(query) |
消し忘れっぽそう
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.
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.
repositoryパッケージで共有
dialectをrepo内で共有するようにしました
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.
sponsors (name, tel, email, address, representative) | ||
VALUES ("` + name + `","` + tel + `","` + email + `","` + address + `","` + representative + `")` | ||
dialect := goqu.Dialect("mysql") | ||
ds := dialect.Insert("sponsors").Rows(goqu.Record{"name": name, "tel": tel, "email": email, "address": address, "representative": representative}) |
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.
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.
なんだろう
公式が使っていたから他に良い名前が思いつかずという感じです
https://github.com/doug-martin/goqu
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.
sponsors (name, tel, email, address, representative) | ||
VALUES ("` + name + `","` + tel + `","` + email + `","` + address + `","` + representative + `")` | ||
dialect := goqu.Dialect("mysql") | ||
ds := dialect.Insert("sponsors").Rows(goqu.Record{"name": name, "tel": tel, "email": email, "address": address, "representative": representative}) |
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.
ds := dialect.Insert("sponsors").Rows(goqu.Record{"name": name, "tel": tel, "email": email, "address": address, "representative": representative}) | |
ds := dialect.Insert("sponsors"). | |
Rows(goqu.Record{ | |
"name": name, | |
"tel": tel, | |
"email": email, | |
"address": address, | |
"representative": representative}) |
長くなりそうならこんな感じにしてもよさそう
lintされないかな勝手に
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.
長くなりそうだなー、
フォーマッターあるならこっちでもいいけど、整形するのにコストかかるな
既存でもそこまで読みにくくないけどどう?
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.
https://github.com/segmentio/golines
長くなるの折り返しならこれ良さそう
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.
`", representative = "` + representative + | ||
`" WHERE id = ` + id | ||
dialect := goqu.Dialect("mysql") | ||
ds := dialect.Update("sponsors").Set(goqu.Record{"name": name, "tel": tel, "email": email, "address": address, "representative": representative}).Where(goqu.Ex{"id": id}) |
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.
ds := dialect.Update("sponsors").Set(goqu.Record{"name": name, "tel": tel, "email": email, "address": address, "representative": representative}).Where(goqu.Ex{"id": id}) | |
ds := dialect.Update("sponsors"). | |
Set(goqu.Record{ | |
"name": name, | |
"tel": tel, | |
"email": email, | |
"address": address, | |
"representative": representative}). | |
Where(goqu.Ex{"id": id}) |
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.
years.year = ` + year + | ||
" ORDER BY sponsors.id;" | ||
dialect := goqu.Dialect("mysql") | ||
query, _, err := dialect.Select("sponsors.*").From("sponsors").InnerJoin(goqu.I("year_periods"), goqu.On(goqu.I("sponsors.created_at").Gt(goqu.I("year_periods.started_at")), goqu.I("sponsors.created_at").Lt(goqu.I("year_periods.ended_at")))).InnerJoin(goqu.I("years"), goqu.On(goqu.I("year_periods.year_id").Eq(goqu.I("years.id")))).Where(goqu.Ex{"years.year": year}).Order(goqu.I("sponsors.id").Desc()).ToSQL() |
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.
query, _, err := dialect.Select("sponsors.*").From("sponsors").InnerJoin(goqu.I("year_periods"), goqu.On(goqu.I("sponsors.created_at").Gt(goqu.I("year_periods.started_at")), goqu.I("sponsors.created_at").Lt(goqu.I("year_periods.ended_at")))).InnerJoin(goqu.I("years"), goqu.On(goqu.I("year_periods.year_id").Eq(goqu.I("years.id")))).Where(goqu.Ex{"years.year": year}).Order(goqu.I("sponsors.id").Desc()).ToSQL() | |
query, _, err := dialect.Select("sponsors.*"). | |
From("sponsors"). | |
InnerJoin(goqu.I("year_periods"), | |
goqu.On(goqu.I("sponsors.created_at").Gt(goqu.I("year_periods.started_at")), | |
goqu.I("sponsors.created_at").Lt(goqu.I("year_periods.ended_at")))).InnerJoin(goqu.I("years"), | |
goqu.On(goqu.I("year_periods.year_id"). | |
Eq(goqu.I("years.id")))). | |
Where(goqu.Ex{"years.year": year}). | |
Order(goqu.I("sponsors.id").Desc()).ToSQL() |
ここいい感じにならない。。。
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.
sponsors (name, tel, email, address, representative) | ||
VALUES ("` + name + `","` + tel + `","` + email + `","` + address + `","` + representative + `")` | ||
dialect := goqu.Dialect("mysql") | ||
ds := dialect.Insert("sponsors").Rows(goqu.Record{"name": name, "tel": tel, "email": email, "address": address, "representative": representative}) |
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.
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.
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.
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.
mergeされたらslackで共有します
prの備考にも追記しておきました
https://nut-m-e-g.slack.com/archives/C020WQ3GY07/p1734923921611839
概要
goquの採用理由
テスト項目
備考
run on save拡張機能をインストールしてください
https://github.com/segmentio/golines