Slide 1

Slide 1 text

TinyGoͰ࢖͑ΔORM sqllaͷ ঺հͱTinyGoͰ࢖͑ΔΑ͏ʹ ͢ΔͨΊͷ޻෉ Asakusa.go #1 @mackee_w a.k.a

Slide 2

Slide 2 text

୭ • @mackee_w at Twitter(formally X), @mackee at GitHub • ໘ന๏ਓΧϠοΫ (ຊ೔ח૔͔Βདྷ·ͨ͠ʂ) • ISUCON11༏উ • ISUCON12༧બ ग़୊(SQLiteͷ΍ͭͰ͢) • ීஈ͸PerlίϛϡχςΟͰ฻Β͍ͯ͠·͢ ͕࢓ࣄ͸΄ͱΜͲGoͰ͢ • YAPC::Hiroshima͍ͬͯ͏Ξπ͍Πϕϯτ͕དྷ೥݄̎ʹ͋ΔͷͰདྷͯ͘Εʂʂʂ

Slide 3

Slide 3 text

TinyGoΛझຯͷ૊ΈࠐΈϓϩάϥϛϯάͰ࢖ͬ ͍ͯ·͢

Slide 4

Slide 4 text

sqlla ͱ͍͏ORMΛ࡞͍ͬͯ·͢ • ΧϥϜʹରԠ͢Δϝ ιουΛੜ੒ͯ͠ SQLΛGoͷจ๏Ͱॻ ͚ΔΫΤϦϏϧμʔ • re fl ectΛ༻͍ͳ͍ ίʔυੜ੒ʹΑΔ structϚοϐϯά ࢓ࣄͰ୲౰͍ͯ͠ΔWebαʔϏεͰࠓ೔΋ݩؾʹಈ͍͍ͯ·͢

Slide 5

Slide 5 text

࠷ۙ΍ͬͨτʔΫ https://speakerdeck.com/mackee/goxiang-keorm-sqllanoshao-jie-to-joinyaunionwohan- ndakuerinoxi-ifang

Slide 6

Slide 6 text

Cloud fl are D1

Slide 7

Slide 7 text

github.com/syumai/workersͰD1͕࢖͑Δʂ

Slide 8

Slide 8 text

Ͱ͖Ε͹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ͷϑϩϯτʹஔ͍͍ͯΔ

Slide 9

Slide 9 text

ͱ͍͏͜ͱͰsqllaΛCloud fl are Workers + TinyGoͰಈ͔ͯ͠ΈΔ

Slide 10

Slide 10 text

DBεΩʔϚΛఆٛ

Slide 11

Slide 11 text

DBεΩʔϚΛఆٛ $ go generate ./

Slide 12

Slide 12 text

connectionΛ༻ҙ

Slide 13

Slide 13 text

Chatॻ͖ࠐΈΤϯυϙΠϯτΛ࣮૷

Slide 14

Slide 14 text

Chatॻ͖ࠐΈΤϯυϙΠϯτΛ࣮૷ ͍ͭ΋࢖͍ͬͯΔ github.com/julienschmidt/httprouter ͕࢖͑ͣ ࣗલͰศརwrapperΛ࣮૷͍ͯ͠·͢

Slide 15

Slide 15 text

Ұ୴Ϗϧυ…΋ग़དྷͣ

Slide 16

Slide 16 text

go-sql-driver/mysql΁ͷϥϯλΠϜͷґଘΛ֎͢ • sqlla͸ੜ੒༻ͷίʔυͱϥϯλΠϜͰ࢖͏ίʔυ͕Ұମʹͳ͍ͬͯΔ • ϥϯλΠϜίʔυͷҰ෦Ͱgo-sql-driver/mysqlΛimport͍ͯ͠Δ • mysql.NullTimeΛϚοϐϯά͢Δίʔυ(ޙํޓ׵ͷͨΊ࢒ͯ͋͠Δ) • D1Ͱ͸࢖Θͳ͍ͷͰɺͦ΋ͦ΋ϏϧυλάͰ֎͢ • ͦͷଞίʔυੜ੒Ͱ͔͠࢖Θͳ͍ίʔυ͸ϏϧυλάΛ͚ͭΔ

Slide 17

Slide 17 text

go-sql-driver/mysql΁ͷϥϯλΠϜͷґଘΛ֎͢

Slide 18

Slide 18 text

go-sql-driver/mysql΁ͷϥϯλΠϜͷґଘΛ֎͢ ϏϧυͰ͖ΔΑ͏ʹ ͳͬͨʂ

Slide 19

Slide 19 text

΄ͳදࣔͰ͖Δ Α͏ʹ͠Α͔ʙ

Slide 20

Slide 20 text

΄ͳදࣔͰ͖Δ Α͏ʹ͠Α͔ʙ !! දࣔ͞Εͳ͍ !!

Slide 21

Slide 21 text

html/templateͰม਺ճ͢ͱ͜ΖͰࢮΜͰ͍Δ • ͜Ε΋͔֬ʹre fl ect࢖͏ͳ͋ • TinyGo͸re fl ect΍socket࢖͏ܥَ͕໳ͳײ͡(ؒҧͬͯͨΒڭ͑ͯ͘ ͍ͩ͞) • encoding/json ͸࢖͑Δ

Slide 22

Slide 22 text

͓ͱͳ͘͠ JSONͰฦ͢ ΤϯυϙΠ ϯτ࡞ͬͯ fetchͰऔΔ Α͏ʹͨ͠

Slide 23

Slide 23 text

ಈ͘Α͏ʹͳΓ·ͨ͠

Slide 24

Slide 24 text

ͦͷଞࠔͬͨ͜ͱ • 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ʆ

Slide 25

Slide 25 text

࣮͸ࠔ͍ͬͯΔ͜ͱ • Cloud fl are Workersʹdeploy͢ΔͱSELECT͕ࣦഊ͢Δ • `panic: syscall/js: Value.Call: property close is not a function, got unde fi ned` • ެࣜGoίϯύΠϥͰ΋ࣦഊ͢Δ • લ͸௨ͬͯͨΑ͏ͳ… • INSERT͸௨Δ • (syumai͞Μʹ૬ஊ͍ͨ͠…)

Slide 26

Slide 26 text

Θ͋ʂ͜Μͳͷ΋ग़ͨʂ

Slide 27

Slide 27 text

Ҏ্ʂ