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
840
perlをWebAssembly上で動かすと何が嬉しいの??? / Where does Perl-on-Wasm actually make sense?
mackee
0
1.4k
Agentに至る道 〜なぜLLMは自動でコードを書けるようになったのか〜
mackee
6
6.6k
今!ソフトウェアエンジニアがハードウェアに手を出すには
mackee
14
7.6k
ワンバイナリWebサービスのススメ
mackee
10
9.2k
tanukistack ライブコーディング / tanukistack live-coding
mackee
0
900
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.2k
Other Decks in Programming
See All in Programming
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
910
iOSDC2026登壇資料.pdf
riofujimon
0
210
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
320
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
470
Are APIs Still Relevant in the AI Era?
soyuka
0
420
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
270
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
360
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
680
AWSに止められる覚悟してますか?
morizo_1984
2
510
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
FreeBSDでZabbixを動かす
kenkino
0
360
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
120
Featured
See All Featured
From π to Pie charts
rasagy
1
390
ラッコキーワード サービス紹介資料
rakko
1
5.2M
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8k
Designing Experiences People Love
moore
143
24k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
450
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
610
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Believing is Seeing
oripsolob
1
240
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
490
Six Lessons from altMBA
skipperchong
29
4.5k
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ͷఏҊ͕͞Εͨ࣌ʹʮδΣωϦΫεΛͬ ͯͶʯͱ͍͏ʹͳ͍ͬͯͨ
Ҏ্ʂ