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
650
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
650
Other Decks in Programming
See All in Programming
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5k
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
410
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
120
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
500
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8k
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
21
21k
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
150
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
34
16k
Agents on Rails - Rails at Scale 2026
irinanazarova
0
350
Workers Cache を知る
syumai
0
350
プロダクトコードからライブラリの境界を見つける
elmetal
PRO
0
110
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Discover your Explorer Soul
emna__ayadi
2
1.3k
Making Projects Easy
brettharned
120
6.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
450
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
510
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
870
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
390
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
620
The agentic SEO stack - context over prompts
schlessera
0
970
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
480
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