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.2k
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
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
perl for shell, awk and sed programmers
mackee
2
1.5k
今更GoのWebフレームワークを作ろうとしているワケ / Why am I trying to create a Go web framework now?
mackee
1
69
マイクロサービス化を利用した Goへの移行事例
mackee
0
120
PerlでつくるフルスクラッチWebAuthn/パスキー認証 / Demonstration of full-scratch WebAuthn/Passkey Authentication written in Perl
mackee
3
3.4k
SRE定例やその辺の取り組みをアプリケーションエンジニア目線で語る / "Observe" about SRE Meeting by Application Engineer
mackee
0
1.8k
Go向けORM sqllaの紹介と JOINやUNIONを含んだクエリの扱い方
mackee
0
4.5k
デプロイ今昔物語 〜CGIからサーバーレスまで〜 / The deployment technics
mackee
10
12k
E2Eテストから負荷試験シナリオを作ってみた / Why do we make a scenario of load testing from E2E testing scenarios
mackee
3
5.5k
Other Decks in Programming
See All in Programming
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
useSyncExternalStoreを使いまくる
ssssota
6
1k
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
선언형 UI에서의 상태관리
l2hyunwoo
0
140
Haze - Real time background blurring
chrisbanes
1
500
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
200
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
160
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
layerx_20241129.pdf
kyoheig3
2
290
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Gamification - CAS2011
davidbonilla
80
5.1k
Speed Design
sergeychernyshev
25
670
Practical Orchestrator
shlominoach
186
10k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
The Pragmatic Product Professional
lauravandoore
32
6.3k
A Tale of Four Properties
chriscoyier
157
23k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Optimizing for Happiness
mojombo
376
70k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
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͞Μʹ૬ஊ͍ͨ͠…)
Θ͋ʂ͜Μͳͷग़ͨʂ
Ҏ্ʂ