Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TinyGoで使えるORM sqllaの 紹介とTinyGoで使えるようにするための工夫
Search
mackee
October 13, 2023
Programming
0
1.5k
TinyGoで使えるORM sqllaの 紹介とTinyGoで使えるようにするための工夫
Asakusa.go #1
https://asakusago.connpass.com/event/295512/
mackee
October 13, 2023
Tweet
Share
More Decks by mackee
See All by mackee
今!ソフトウェアエンジニアがハードウェアに手を出すには
mackee
14
5.4k
ワンバイナリWebサービスのススメ
mackee
10
8.1k
tanukistack ライブコーディング / tanukistack live-coding
mackee
0
120
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
990
perl for shell, awk and sed programmers
mackee
3
2.5k
今更GoのWebフレームワークを作ろうとしているワケ / Why am I trying to create a Go web framework now?
mackee
1
970
database/sqlでNullを扱う歴史とsql.Null[T]の登場 / sql.Null[T] history
mackee
0
850
マイクロサービス化を利用した Goへの移行事例
mackee
0
990
PerlでつくるフルスクラッチWebAuthn/パスキー認証 / Demonstration of full-scratch WebAuthn/Passkey Authentication written in Perl
mackee
3
5.5k
Other Decks in Programming
See All in Programming
Introducing RemoteCompose: break your UI out of the app sandbox.
camaelon
2
420
data-viz-talk-cz-2025
lcolladotor
0
110
Temporal Knowledge Graphで作る! 時間変化するナレッジを扱うAI Agentの世界
po3rin
5
1.2k
なんでRustの環境構築してないのにRust製のツールが動くの? / Why Do Rust-Based Tools Run Without a Rust Environment?
ssssota
14
47k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
480
Kotlinで実装するCPU/GPU 「協調的」パフォーマンス管理
matuyuhi
0
240
Kotlin 2.2が切り拓く: コンテキストパラメータで書く関数型DSLと新しい依存管理のかたち
knih
0
230
TFLintカスタムプラグインで始める Terraformコード品質管理
bells17
2
520
Designing Repeatable Edits: The Architecture of . in Vim
satorunooshie
0
220
ボトムアップの生成AI活用を推進する社内AIエージェント開発
aku11i
0
1.4k
Migration to Signals, Resource API, and NgRx Signal Store
manfredsteyer
PRO
0
140
Claude Agent SDK を使ってみよう
hyshu
0
1.5k
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
38
2.9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.2k
Documentation Writing (for coders)
carmenintech
76
5.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
How GitHub (no longer) Works
holman
315
140k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
KATA
mclloyd
PRO
32
15k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
Transcript
TinyGoͰ͑ΔORM sqllaͷ հͱTinyGoͰ͑ΔΑ͏ʹ ͢ΔͨΊͷ Asakusa.go #1 @mackee_w a.k.a
୭ • @mackee_w at Twitter(formally X), @mackee at GitHub •
໘ന๏ਓΧϠοΫ (ຊח͔Βདྷ·ͨ͠ʂ) • ISUCON11༏উ • ISUCON12༧બ ग़(SQLiteͷͭͰ͢) • ීஈPerlίϛϡχςΟͰΒ͍ͯ͠·͢ ͕ࣄ΄ͱΜͲGoͰ͢ • YAPC::Hiroshima͍ͬͯ͏Ξπ͍Πϕϯτ͕དྷ݄̎ʹ͋ΔͷͰདྷͯ͘Εʂʂʂ
TinyGoΛझຯͷΈࠐΈϓϩάϥϛϯάͰͬ ͍ͯ·͢
sqlla ͱ͍͏ORMΛ࡞͍ͬͯ·͢ • ΧϥϜʹରԠ͢Δϝ ιουΛੜͯ͠ SQLΛGoͷจ๏Ͱॻ ͚ΔΫΤϦϏϧμʔ • re fl
ectΛ༻͍ͳ͍ ίʔυੜʹΑΔ structϚοϐϯά ࣄͰ୲͍ͯ͠ΔWebαʔϏεͰࠓݩؾʹಈ͍͍ͯ·͢
࠷ۙͬͨτʔΫ https://speakerdeck.com/mackee/goxiang-keorm-sqllanoshao-jie-to-joinyaunionwohan- ndakuerinoxi-ifang
Cloud fl are D1
github.com/syumai/workersͰD1͕͑Δʂ
Ͱ͖ΕTinyGoͰಈ͔͍ͨ͠ • Of fi cial Go : 6105.21 KiB /
gzip: 1650.72 KiB • TinyGo: 2215.79 KiB / gzip: 769.47 KiB • Of fi cial Go Compiler൛ͩͱແྉͰΞοϓϩʔυͰ͖ͳ͍ • ※ํ՝͍ۚͯ͠·͢ɻ͓Ұਓ༷misskeyͷϑϩϯτʹஔ͍͍ͯΔ
ͱ͍͏͜ͱͰsqllaΛCloud fl are Workers + TinyGoͰಈ͔ͯ͠ΈΔ
DBεΩʔϚΛఆٛ
DBεΩʔϚΛఆٛ $ go generate ./
connectionΛ༻ҙ
Chatॻ͖ࠐΈΤϯυϙΠϯτΛ࣮
Chatॻ͖ࠐΈΤϯυϙΠϯτΛ࣮ ͍͍ͭͬͯΔ github.com/julienschmidt/httprouter ͕͑ͣ ࣗલͰศརwrapperΛ࣮͍ͯ͠·͢
Ұ୴Ϗϧυ…ग़དྷͣ
go-sql-driver/mysqlͷϥϯλΠϜͷґଘΛ֎͢ • sqllaੜ༻ͷίʔυͱϥϯλΠϜͰ͏ίʔυ͕Ұମʹͳ͍ͬͯΔ • ϥϯλΠϜίʔυͷҰ෦Ͱgo-sql-driver/mysqlΛimport͍ͯ͠Δ • mysql.NullTimeΛϚοϐϯά͢Δίʔυ(ޙํޓͷͨΊͯ͋͠Δ) • D1ͰΘͳ͍ͷͰɺͦͦϏϧυλάͰ֎͢ •
ͦͷଞίʔυੜͰ͔͠Θͳ͍ίʔυϏϧυλάΛ͚ͭΔ
go-sql-driver/mysqlͷϥϯλΠϜͷґଘΛ֎͢
go-sql-driver/mysqlͷϥϯλΠϜͷґଘΛ֎͢ ϏϧυͰ͖ΔΑ͏ʹ ͳͬͨʂ
΄ͳදࣔͰ͖Δ Α͏ʹ͠Α͔ʙ
΄ͳදࣔͰ͖Δ Α͏ʹ͠Α͔ʙ !! දࣔ͞Εͳ͍ !!
html/templateͰมճ͢ͱ͜ΖͰࢮΜͰ͍Δ • ͜Ε͔֬ʹre fl ect͏ͳ͋ • TinyGore fl ectsocket͏ܥَ͕ͳײ͡(ؒҧͬͯͨΒڭ͑ͯ͘ ͍ͩ͞)
• encoding/json ͑Δ
͓ͱͳ͘͠ JSONͰฦ͢ ΤϯυϙΠ ϯτ࡞ͬͯ fetchͰऔΔ Α͏ʹͨ͠
ಈ͘Α͏ʹͳΓ·ͨ͠
ͦͷଞࠔͬͨ͜ͱ • time.TimeΛͦͷ··insert͠Α͏ͱ͢Δͱࢮ͵ • தͰre fl ect͕ΘΕ͍ͯΔͨΊʁ `panic: ValueOf: invalid
value` • int64ʹม͍ͯ͠Δ • ϩʔΧϧϞʔυͩͱ`time.Now`͕ΊͪΌͪ͘Όڰ͍ͬͯΔ • ʆ2077-07-23 14:29:52.008999936 +0900 UTC+9 m=+3394243792.008999937ʆ
࣮ࠔ͍ͬͯΔ͜ͱ • Cloud fl are Workersʹdeploy͢ΔͱSELECT͕ࣦഊ͢Δ • `panic: syscall/js: Value.Call:
property close is not a function, got unde fi ned` • ެࣜGoίϯύΠϥͰࣦഊ͢Δ • લ௨ͬͯͨΑ͏ͳ… • INSERT௨Δ • (syumai͞Μʹ૬ஊ͍ͨ͠…)
Θ͋ʂ͜Μͳͷग़ͨʂ
Ҏ্ʂ