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.4k
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
tanukistack ライブコーディング / tanukistack live-coding
mackee
0
73
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
400
perl for shell, awk and sed programmers
mackee
2
1.9k
今更GoのWebフレームワークを作ろうとしているワケ / Why am I trying to create a Go web framework now?
mackee
1
330
database/sqlでNullを扱う歴史とsql.Null[T]の登場 / sql.Null[T] history
mackee
0
250
マイクロサービス化を利用した Goへの移行事例
mackee
0
380
PerlでつくるフルスクラッチWebAuthn/パスキー認証 / Demonstration of full-scratch WebAuthn/Passkey Authentication written in Perl
mackee
3
4k
SRE定例やその辺の取り組みをアプリケーションエンジニア目線で語る / "Observe" about SRE Meeting by Application Engineer
mackee
0
1.9k
Go向けORM sqllaの紹介と JOINやUNIONを含んだクエリの扱い方
mackee
0
4.8k
Other Decks in Programming
See All in Programming
SideKiqでジョブが二重起動した事象を深堀りしました
t_hatachi
0
230
AtCoder Heuristic First-step Vol.1 講義スライド(山登り法・焼きなまし法編)
takumi152
3
980
自分のために作ったアプリが、グローバルに使われるまで / Indie App Development Lunch LT
pixyzehn
1
120
Let's Take a Peek at PHP Parser 5.x!
inouehi
0
100
Denoでフロントエンド開発 2025年春版 / Frontend Development with Deno (Spring 2025)
petamoriken
1
1.3k
Compose Navigation実装の見通しを良くする
hiroaki404
0
180
eBPF Updates (March 2025)
kentatada
0
130
보일러플레이트 코드가 진짜 나쁜 건가요?
gaeun5744
0
370
体得しよう!RSA暗号の原理と解読
laysakura
3
530
S3静的ホスティング+Next.js静的エクスポート で格安webアプリ構築
iharuoru
0
200
CQRS+ES勉強会#1
rechellatek
0
400
Windows版PHPのビルド手順とPHP 8.4における変更点
matsuo_atsushi
0
370
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
91
5.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
51
2.4k
Side Projects
sachag
452
42k
Building Adaptive Systems
keathley
41
2.5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
12
1.4k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.5k
Agile that works and the tools we love
rasmusluckow
328
21k
How to Ace a Technical Interview
jacobian
276
23k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
How to Think Like a Performance Engineer
csswizardry
22
1.5k
Code Reviewing Like a Champion
maltzj
522
39k
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͞Μʹ૬ஊ͍ͨ͠…)
Θ͋ʂ͜Μͳͷग़ͨʂ
Ҏ্ʂ