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
AIとGame Jamで、ゲームを完成させた話
takahirosaeki
0
110
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
140
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
200
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
110
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
140
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
120
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
Webの地図
yosuke_furukawa
PRO
4
3.6k
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
230
ソフトウェアラスタライザ
fadis
1
800
What We Talk About When We Talk About XP
m_seki
2
450
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
180
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
230
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
270
What's in a price? How to price your products and services
michaelherold
247
13k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.2k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Paper Plane (Part 1)
katiecoart
PRO
1
11k
How to Ace a Technical Interview
jacobian
281
24k
sira's awesome portfolio website redesign presentation
elsirapls
0
410
How to train your dragon (web standard)
notwaldorf
97
6.8k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Design in an AI World
tapps
1
310
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