Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
最速のクエリビルダを妄想してみた
Search
mackee
June 13, 2015
Programming
0
67
最速のクエリビルダを妄想してみた
mackee
June 13, 2015
Tweet
Share
More Decks by mackee
See All by mackee
perl for shell, awk and sed programmers
mackee
2
1.3k
今更GoのWebフレームワークを作ろうとしているワケ / Why am I trying to create a Go web framework now?
mackee
1
63
マイクロサービス化を利用した Goへの移行事例
mackee
0
100
PerlでつくるフルスクラッチWebAuthn/パスキー認証 / Demonstration of full-scratch WebAuthn/Passkey Authentication written in Perl
mackee
3
3.2k
SRE定例やその辺の取り組みをアプリケーションエンジニア目線で語る / "Observe" about SRE Meeting by Application Engineer
mackee
0
1.8k
TinyGoで使えるORM sqllaの 紹介とTinyGoで使えるようにするための工夫
mackee
0
1.1k
Go向けORM sqllaの紹介と JOINやUNIONを含んだクエリの扱い方
mackee
0
4.4k
デプロイ今昔物語 〜CGIからサーバーレスまで〜 / The deployment technics
mackee
10
12k
E2Eテストから負荷試験シナリオを作ってみた / Why do we make a scenario of load testing from E2E testing scenarios
mackee
3
5.4k
Other Decks in Programming
See All in Programming
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
Realtime API 入門
riofujimon
0
150
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Ethereum_.pdf
nekomatu
0
460
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
100
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Become a Pro
speakerdeck
PRO
25
5k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Making Projects Easy
brettharned
115
5.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Six Lessons from altMBA
skipperchong
27
3.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Transcript
࠷ͷΫΤϦϏϧμΛ ໝͯ͠Έͨ @mackee_w a.k.a Ϛίϐʔ ΠΧID: mackee_w
YAPCԠื͍ͯ͠·͢ • http://yapcasia.org/2015/talk/show/ a668ef3e-080b-11e5-b2b4-79c97d574c3a • Ͳ͏ͯ͠PerlͰυϩʔϯΛඈ͍ͨ͠ਓͷͨ ΊͷϋʔυΣΞϋοΫ֓ • ·ͨͷ໊Λୁั͞Εͳ͍ͨΊʹυϩʔϯΛඈ ͨ͢Ίͷ97ͷ͜ͱ
GoͷΫΤϦϏϧμ • lann/squirrel import sq “github.com/lann/squirrel” query, args, err :=
sq.Select(“id”, “name”).From(“user”).Where(sq.Eq{“id”: id}).ToSql() row := db.QueryRow(query, args…)
sq.Where(sq.Eq{“id”: id}) ↑͍ͭ͜ϦϑϨΫγϣϯ
ͦsquirrelΫΤϦϏϧμ • ΫΤϦϏϧμͳͷͰεΩʔϚΛΒͳ͍ • εΩʔϚΛΒͳ͍ͷͰΧϥϜͷܕΛΒͳ ͍ • ͱ͍͏͔interface{}ͳͷͰͳΜͰಥͬࠐΊΔ • errorͱ͔ಥͬࠐΊΔɺͦͯ͠panicΔ
ϦϑϨΫγϣϯͷޭࡑ • ϦϑϨΫγϣϯʹΑΓͱΓ͋͑ͣinterface{}Ͱ ड͚ͯͦͷޙͷ͜ͱޙͰߟ͑ΔΈ͍ͨͳ͜ ͱ͕ग़དྷΔ • ͦͷΘΓʹಈ͍͍ͯΔͱ͖ʹpanicΔͷͰਓ ͕͕ؒΜͬͯpanicΒͳ͍Α͏ʹಥͬࠐΉ ͷΛࢹ͠ͳ͚ΕͳΒͳ͍
ܕͱԿͩͬͨͷ͔ (GoܕϏονݴޠͱ͍͏ ͜͜Ͱແࢹ͓ͯ͘͠)
sqlla - a pre- generated structure query buillder - ͔࣍ΒໝͰ͢
go generate • Go1.4͔Βgo generateͱ͍͏Έ͕Ճ ͞Εͨ • //go:generate hogehoge •
͜ΕΛهड़ͨ͠ιʔε͕ଘࡏ͢Δͱ͜ΖͰgo generateͬͯίϚϯυΛଧͭͱhogehogeͬͯ ͍͏ͷ͕γΣϧͰ࣮ߦ͞ΕΔ
༻ྫ • https://godoc.org/golang.org/x/tools/cmd/ stringer จࣈྻԽग़དྷΔఆΛ࡞ΔͨΊͷ generater • ఆͷ্ʹίϝϯτͰΞϊςʔγϣϯΛ࡞Δ ͱ fmt.Stringerͱ͍͏interfaceΛ࣮ͨ͠type
Λఆٛͯ͠จࣈྻԽग़དྷͯศར
argen • ੩తղੳϕʔεͷORM • //+ARͬͯstructʹॻ͘ͱ͍Ζ͍Ζ࣮ͯ͘͠ ΕΔ(?)
genddl • ࡞ͷDDLੜث • //+table: <ςʔϒϧ໊>ͬͯstructʹॻ͍ͯΧ ϥϜ໊ͱ͔ΛλάͰॻ͘ͱDDLΛੜͯ͘͠ ΕΔ
ಓ۩ • go/parser + go/ast • text/template
ࠓճໝͨ͠ͷ • ੩తղੳϕʔεͷΫΤϦϏϧμ import ( “github.com/mackee/sugoiapp/schema/user” ) user.UserId{1}.Name{“name”}.ToSql()
த //+table: user type User struct { Id uint64 `db:”id”`
Name string `db:”name”` }
͔͜͜Βauto generated type Name struct { Name string Expr sqlla.Expr
} func (c Name) ToSql() { return “name “ + c.Expr.ToSql() + “?” }
͋ͱϝιουνΣΠϯͱ͔ ͕ΜͬͯࣗಈੜϫΠϫ Π ྗٕ͡Ό
ͱ͍͏ͷΛ1࣌ؒલʹࢥ͍ͭ ͍ͨͷͰɺͦͷ͏࣮ͪ͠ͱ ͜(͜Ε͕Φν)