Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
最速のクエリビルダを妄想してみた
Search
mackee
June 13, 2015
Programming
89
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
最速のクエリビルダを妄想してみた
mackee
June 13, 2015
Transcript
18 slides
࠷ͷΫΤϦϏϧμΛ ໝͯ͠Έͨ @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࣌ؒલʹࢥ͍ͭ ͍ͨͷͰɺͦͷ͏࣮ͪ͠ͱ ͜(͜Ε͕Φν)
More Decks by mackee
See All by mackee
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
900
perlをWebAssembly上で動かすと何が嬉しいの??? / Where does Perl-on-Wasm actually make sense?
mackee
0
1.6k
Agentに至る道 〜なぜLLMは自動でコードを書けるようになったのか〜
mackee
6
7k
今!ソフトウェアエンジニアがハードウェアに手を出すには
mackee
14
7.8k
ワンバイナリWebサービスのススメ
mackee
10
9.4k
tanukistack ライブコーディング / tanukistack live-coding
mackee
0
1k
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
1.2k
perl for shell, awk and sed programmers
mackee
3
3k
今更GoのWebフレームワークを作ろうとしているワケ / Why am I trying to create a Go web framework now?
mackee
1
1.2k
Other Decks in Programming
See All in Programming
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
2
500
Kotlin Fest 2026: Kotlin コンパイラに Contribute してみよう! - Kotlin/Wasm で深い再帰を書けるようにした話
ternbusty
1
400
Beyond Chatbots: Agentic UI with Open Standards @W-JAX 2026, München
manfredsteyer
PRO
0
120
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
220
SODA - FACT BOOK(JP)
sodainc
1
40k
小さなアプリを作って公開するまで
onozaty
0
210
Distance field of Julia set
kinakomoti321
0
330
はじめてのPLATEAU
nokonoko1203
1
660
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
690
Getting Started with Vibe Coding
miccheng
0
240
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
680
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
190
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
390
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
A Soul's Torment
seathinner
9
3.9k
The Art of Programming - Codeland 2020
erikaheidi
57
15k
Un-Boring Meetings
codingconduct
0
500
Google's AI Overviews - The New Search
badams
0
1.7k
The Language of Interfaces
destraynor
162
27k
Exploring anti-patterns in Rails
aemeredith
4
570
Into the Great Unknown - MozCon
thekraken
41
2.8k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
1
250