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
ワンバイナリWebサービスのススメ
mackee
10
7.8k
tanukistack ライブコーディング / tanukistack live-coding
mackee
0
110
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
690
perl for shell, awk and sed programmers
mackee
2
2.3k
今更GoのWebフレームワークを作ろうとしているワケ / Why am I trying to create a Go web framework now?
mackee
1
650
database/sqlでNullを扱う歴史とsql.Null[T]の登場 / sql.Null[T] history
mackee
0
540
マイクロサービス化を利用した Goへの移行事例
mackee
0
670
PerlでつくるフルスクラッチWebAuthn/パスキー認証 / Demonstration of full-scratch WebAuthn/Passkey Authentication written in Perl
mackee
3
4.6k
SRE定例やその辺の取り組みをアプリケーションエンジニア目線で語る / "Observe" about SRE Meeting by Application Engineer
mackee
0
1.9k
Other Decks in Programming
See All in Programming
ふつうの技術スタックでアート作品を作ってみる
akira888
1
1.1k
Rails Frontend Evolution: It Was a Setup All Along
skryukov
0
240
The Niche of CDK Grant オブジェクトって何者?/the-niche-of-cdk-what-isgrant-object
hassaku63
1
500
RailsGirls IZUMO スポンサーLT
16bitidol
0
190
The Evolution of Enterprise Java with Jakarta EE 11 and Beyond
ivargrimstad
0
180
ISUCON研修おかわり会 講義スライド
arfes0e2b3c
1
460
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
Deep Dive into ~/.claude/projects
hiragram
14
11k
AIともっと楽するE2Eテスト
myohei
8
2.9k
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
240
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
2
14k
What's new in AppKit on macOS 26
1024jp
0
140
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
184
22k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
Automating Front-end Workflow
addyosmani
1370
200k
Done Done
chrislema
184
16k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
980
Facilitating Awesome Meetings
lara
54
6.5k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.7k
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͞Μʹ૬ஊ͍ͨ͠…)
Θ͋ʂ͜Μͳͷग़ͨʂ
Ҏ্ʂ