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
database/sqlでNullを扱う歴史とsql.Null[T]の登場 / sql.Nul...
Search
mackee
May 17, 2024
Programming
1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
database/sqlでNullを扱う歴史とsql.Null[T]の登場 / sql.Null[T] history
kamakura.go #6
https://kamakurago.connpass.com/event/316438/
mackee
May 17, 2024
More Decks by mackee
See All by mackee
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
820
perlをWebAssembly上で動かすと何が嬉しいの??? / Where does Perl-on-Wasm actually make sense?
mackee
0
1.3k
Agentに至る道 〜なぜLLMは自動でコードを書けるようになったのか〜
mackee
6
6.4k
今!ソフトウェアエンジニアがハードウェアに手を出すには
mackee
14
7.5k
ワンバイナリWebサービスのススメ
mackee
10
9.2k
tanukistack ライブコーディング / tanukistack live-coding
mackee
0
840
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
1.2k
perl for shell, awk and sed programmers
mackee
3
2.9k
今更GoのWebフレームワークを作ろうとしているワケ / Why am I trying to create a Go web framework now?
mackee
1
1.1k
Other Decks in Programming
See All in Programming
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
330
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
120
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
0
280
What We Talk About When We Talk About XP
m_seki
2
620
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
6
1.9k
Building an Out-of-Order CPU
latte72
1
780
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
400
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
270
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
390
スマート反転とウェブアクセシビリティ
camiha
0
210
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
140
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
460
Featured
See All Featured
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
460
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
520
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Bash Introduction
62gerente
615
220k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
420
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
540
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
540
Optimising Largest Contentful Paint
csswizardry
37
4k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
430
The Curious Case for Waylosing
cassininazir
1
510
Transcript
database/sqlͰNULLΛѻ͏ ྺ࢙ͱsql.Null[T]ͷొ kamakura.go #6 @mackee_w a.k.a macopy 2024-05-17
Δਓ • X: @mackee_w • GitHub: @mackee • ໘ന๏ਓΧϠοΫ •
Tonamel αʔόʔαΠυΤϯδχΞ
database/sqlͰNULLΛѻ͏ ͱʁ
database/sqlͰNULLΛѻ͏
database/sqlͰNULLΛѻ͏ • sql.Null**ͱ͍͏ܕͰϥοϓͯ͠ग़͠ೖΕΛ͢Δ • ϙΠϯλܕͰͳ͍(͕ɺϙΠϯλܕͷnilΛαϙʔτ͍ͯ͠Δέʔε͋Δ) • sql.Null**Validͱ͍͏ϑΟʔϧυ͕͋Δ • Valid͕falseͩͱNull, trueͩͱNullͰͳ͍
• ValidͱผʹΛ֨ೲ͢ΔϑΟʔϧυ͕͋Δ • sql.NullStringͰ͋Ε `String string`, sql.NullInt64Ͱ͋Ε`Int64 int64`
ͦͦdatabase/sqlͰѻ͏ͬͯͳΜͩʁ • جຊతʹҎԼͷinterface͕࣮͞Ε͍ͯΔܕ • SQLͷͱͯ͠͏߹ database/sql/driver.Valuer • ΫΤϦͷ݁Ռ͔Βड͚औͬͨͷΛGoͷมʹόΠϯυ͢Δ߹ɺ database/sql.Scanner •
GoͷϓϦϛςΟϒܕdriverྀ͕͍ͯ͠Δܕͦͷ··ಥͬࠐΊΔ • ޙऀͷྫ: json.RawMessage(go-sql-driver/mysql)
driver.ValuerͰNULLΛSQLʹೖΕΔʹ • driver.Valuer.Value()͕nilΛฦͤྑ͍ • sql.Null**ͳͲͦ͏ͳ͍ͬͯΔ • driver.Valuer.Value()͕typed-nilΛฦͨ͠߹ʁ • driver͘͠database/sql/driverͰuntyped-nilʹม͞Ε͍ͯΔ ͷͰηʔϑ
• Ͱuntyped-nilΛฦͨ͠ํ͕(͓ߦّ)ྑ͍Ͱ͢Ͷ
driver.ScanͰNULLΛड͚Δʹʁ • driver.Scanner.Scanʹuntyped-nil͕ೖͬͯ͘ΔͷͰɺͦΕͰValidͷ ఆΛߦ͏ • sql.Null**ʹnil͕ೖͬͨ߹Validʹfalse͕ೖΓɺ͕ೖΔ fi eldʹθ ϩ͕ೖΔΑ͏ʹͳ͍ͬͯΔ •
driver.ScannerͰͳ͘ϙΠϯλܕͰnullΛड͚ͨΒnil͕ೖΔ • Ͱθϩnilͱݟ͚͕͔ͭͳ͍͔ʁ ؾ͕͢Δ͚ͩͳͷͰ۩ମతͳ έʔε͕͋ͬͨΒڭ͍͑ͯͩ͘͞
database/sqlʹ͓͚Δsql.Null**ͷྺ࢙ • sql.NullStringdatabase/sqlύοέʔδ͕࡞ΒΕͨ࣌Ͱଘࡏ͢Δ(2011/09/29) • ࣌sql.NullableStringͱ͍͏໊લͰScannerInfo interface͕࣮͞Ε͍ͯͨ • sql.NullInt64, sql.NullFloat64, sql.BoolՃ(2012/01/26)
• ͜ͷޙgo1͕ϦϦʔε • sql.NullTimeՃ(2019/04/06), sql.NullInt32Ճ(2019/04/27), sql.NullInt16, sql.NullBytesՃ(2021/05/05)
Β͘sql.NullTime͕ͳ͔ͬͨ • ͳ͔ͬͨͷͰgo-sql-driver/mysql.NullTimeΛ͍ͬͯͨਓ͍ͨͰ ͠ΐ͏(2013/04/26͔Βଘࡏ) • ͦͷଞsql.Null**(͜͜ʹҙͷܕ͕ೖΔ)͕ཉ͍͠ํ͍ͬͺ͍͍ͨͰ ͠ΐ͏ • ϥΠϒϥϦͳΓࣗલ࣮ͳΓ͕ඞཁͰ͋ͬͨ… •
ͦΕͦΕͰϓϩδΣΫτ͝ͱʹҧ͏ͱ͍͏ࠞཚͷͱʹ…
from Go1.22 Release Notes The new Null[T] type provide a
way to scan nullable columns for any column types.
sql.Null[T]ͱ • sql.Null[T(͜͜ʹҙͷܕ͕ೖΔ)]ͷΑ͏ʹ༻͢Δ͜ͱͰɺsql.Null**ͱಉ͡ޮ ྗΛ࣋ͭܕ • sql.Null**Λ૿͞ͳͯ͘ྑ͘ͳͬͨʂ • user de fi
ned typeͱͷΈ߹Θ͕ͤྑ͍ • type HogeID uint64 ͷΑ͏ͳIDܕ࡞ͬͨ߹ʹɺͦͷNullableͳܕͱͯ͠ `sql.Null[HogeID]`͕͑Δ • methane͞ΜฒͼʹGoνʔϜͷօ͞Μ͋Γ͕ͱ͏ʂ
FAQ • Q: ࣮࣭Option/MaybeܕͰʁ • A: IssueʹͦΜͳ͕ٞ͋Γ·͕ͨ͠ɺSQLΛॻ͘ͱ͖ɺDB͔Βͷ ΫΤϦ݁ՌΛಡΉ࣌ʹͷΈ͍·͠ΐ͏Ͷ • Q:
͜Ε͕ೖͬͨܦҢʁ • A: ͱͱsql.NullUInt64ͷఏҊ͕͞Εͨ࣌ʹʮδΣωϦΫεΛͬ ͯͶʯͱ͍͏ʹͳ͍ͬͯͨ
Ҏ্ʂ