Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Go向けORM sqllaの紹介と JOINやUNIONを含んだクエリの扱い方

mackee
August 26, 2023

Go向けORM sqllaの紹介と JOINやUNIONを含んだクエリの扱い方

mackee

August 26, 2023
Tweet

More Decks by mackee

Other Decks in Programming

Transcript

  1. sqllaͷചΓ • ςʔϒϧͷΧϥϜʹରԠͨ͠ϝιου͕ίʔυੜ੒͞ΕΔͷͰɺิ׬ ʹग़ͯ͘Δ • `column IN (…)`, όϧΫΠϯαʔτ, `INSERT

    ~ ON DUPLICATEKEY UPDATE` ʹରԠ • ϑϨʔϜϫʔΫ΍ύοέʔδߏ੒ʹڧ͘ґଘ͠ͳ͍ͷͰɺҰ෦෼͚ͩ sqllaΛೖΕΔ͜ͱ͕Մೳ
  2. Django ORM, SQLAlchemy, Peewee, Pony ORM, Tortoise ORM, Hibernate, EclipseLink,

    JOOQ, MyBatis, ActiveJDBC, ActiveRecord, Sequel, DataMapper, Entity Framework, Dapper, LINQ to SQL, Massive, Eloquent ORM, Doctrine ORM, Propel, Sequelize, TypeORM, Waterline, Objection.js, GORM, xorm, Storm, Pop, Exposed, Ktorm, OrmLite ChatGPTʹͰ͖Δ͚ͩྻڍͯ͠ͱ͓ئ͍ͨ͠(ͳ͍΋ͷ͕͋Δ͔΋)
  3. sqlla͚ͩͩͱ͖͍ͭͷͰɺݱ࣮తʹ͸͜͏ͯ͠ ·͢ • εΩʔϚ؅ཧ github.com/mackee/go-genddl • sqllaޓ׵ͷstruct͔ΒDDLΛग़ྗ͢Δ • εΩʔϚϚΠάϨʔγϣϯ github.com/k0kubun/sqldef

    • DDL͔ΒALTERจΛੜ੒͢Δ • ίωΫγϣϯ؅ཧ database/sql • ΧϥϜͷܕͱGoͷܕͷ૬ޓม׵͸֤driverʹ೚͍ͤͯΔ • ήετͷshogo82148͞Μ(go-sql-driver/mysqlͷίϯτϦϏϡʔλʔ)ײँͯ͠·͢ʂ
  4. ՝୊ • Where۟༻ͷϝιουͰ໊લ͕ඃͬͨΒͲ͏͢Δͷ͔ • Account.ID͸AccountID(v, operator…)ʹͳΔ͕ɺ͜ͷ๏ଇͰ͍͘ͱඃͬͯ͠·͏͜ͱ͕͋Δͷ Ͱ͸ɾɾɾʁ • Ҋ֎ͳ͍͔΋ʁ •

    εΩʔϚϚΠάϨʔγϣϯ࣌ʹϏϡʔͷΧϥϜ͕৯͍ҧͬͯഁ໓͠ͳ͍͔Ͳ͏͔ • ςετͰΘ͔Δ͔Βେৎ෉ʁɹͨͩ `u.*` Έ͍ͨͳࢦఆΛ͢ΔͱɺDML࣮ߦத͏ʹരൃ͢Δ͔΋ • MySQLͰsqldefΛ࢖͏ࡍʹϏϡʔΛؚΜͩDDLΛ࢖͏ͱৗʹࠩ෼͕ൃੜ͢Δ • ຊମʹڍಈΛվળ͢ΔPull RequestΛૹΕͳ͍͔ௐࠪத… ࠙਌ձͰ୭͔ʹฉ͔͘΋