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
sqlcを利用してsqlに型付けを
Search
kamiyam
October 02, 2024
Programming
640
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
sqlcを利用してsqlに型付けを
kamiyam
October 02, 2024
More Decks by kamiyam
See All by kamiyam
useImperativeHandle を迷いながら使った話
kamiyam
0
89
GraphQLで使うデータに TypeScriptで型を定義する
kamiyam
1
640
Other Decks in Programming
See All in Programming
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
460
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
130
MIZARU@SPAJAM2026 第二回予選
1901drama
0
110
AIとGame Jamで、ゲームを完成させた話
takahirosaeki
0
110
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
130
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
490
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
PHPプロジェクトの結合バランスを可視化する #php_night
kajitack
0
230
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
120
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
3
520
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
140
Featured
See All Featured
Claude Code のすすめ
schroneko
67
230k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
How to Ace a Technical Interview
jacobian
281
24k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.3k
Facilitating Awesome Meetings
lara
57
7.1k
Transcript
sqlcΛར༻ͯ͠sqlʹܕ͚Λ kansai.ts #8 2024.10.2 @kamiyam
ࣗݾհ ͔ΈΜ (Twitter@kamiyam) ݩࣗಈंඋ࢜ METEORWORKS Inc. Engineer ϑϩϯτʙ όοΫΤϯυNode.jsશൠ
What is sqlc?
IUUQTTRMDEFW
TRMDHFOFSBUF TRMDZNMΛར༻ͯ͠ίʔυΛੜ͢Δ IUUQTEPDTTRMDEFWFOMBUFTUIPXUPHFOFSBUFIUNM
sqlcࣗମCLIπʔϧͱͯ͠ Πϯετʔϧ͢ΔܗͰར༻͢Δ͜ͱʹͳΔ (MacͳΒbrewͳͲ)
None
SQLϑΝΠϧΛಡΈऔͬͯɺgoίʔυΛੜ͢Δπʔϧ
Goݴޠ?
IUUQTHJUIVCDPNTRMDEFWTRMDHFOUZQFTDSJQU
None
plugin ͱͯ͠ TypeScript͚ SQLϑΝΠϧ͔Βܕ҆શͳίʔυΛੜ͢Δ
None
Supported engines and drivers - PostgreSQL via pg or postgres.
- MySQL via mysql2. - SQLite via sqlite3.
ڥʹsqlcΛΠϯετʔϧ͢ΔͷΛආ͚ DockerΛ͔Β࣮ߦ͢Δํ๏
None
How to use sqlc.
IUUQTHJUIVCDPNTRMDEFWTRMDHFOUZQFTDSJQUCMPC NBJOFYBNQMFTBVUIPSTNZTRMRVFSZTRM
IUUQTEPDTTRMDEFWFOTUBCMFSFGFSFODFRVFSZBOOPUBUJPOTIUNM
%&.0
Tips. PostgreSQL ͷํ͕खް͘αϙʔτͯͦ͠͏ MySQL Ͱ insertޙͷid ͢Β… ϚΠάϨʔγϣϯʹରԠ͍ͯ͠ͳ͍ͷͰ ผͷϥΠϒϥϦΛ͏ඞཁ͕͋Δ
Refs. Compile SQL to type-safe code; catch failures before they
happen. https://sqlc.dev/ generate - Generating code https://docs.sqlc.dev/en/latest/howto/generate.html sqlc-gen-typescript https://github.com/sqlc-dev/sqlc-gen-typescript sqlc-gen-typescriptͰMySQLͰinsertޙͷID͕΄͍͠ https://qiita.com/Yuumillar/items/b1e3ec74eac725834735
sqlc-gen-typescript ͷ࠷৽ίʔυΛϏϧυͯ͠ v0.1.3Ͱར༻Ͱ͖ͳ͍ execlastid Λར༻͢Δ
None
ϩʔΧϧͷίϚϯυͰ͍͚Δ͕ EPDLFSͰ͏·͍͔ͣ͘ʜ
Why use sqlc?
rLBNJZBN lͦΕͧΕͷ03Ϛούʔͷهड़Λ֮͑ΔͷͰ͋Ε 42-Λॻ͍ͨํ͕͍͍ʢ͔͠Εͳ͍ʣz
ͳ͓sqlc(-gen-typescript)Λ͓͏ͱࢥͬͯ ϓϩδΣΫτͷnextϒϥϯνʹೖΕͨཌ
None
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠
Refs. Announcing TypedSQL: Make your raw SQL queries type-safe with
Prisma ORM https://www.prisma.io/blog/announcing-typedsql-make-your-raw-sql- queries-type-safe-with-prisma-orm