Closed15

ent (An entity framework for Go)を調査してみる

おでんおでん

最近発見したentが大変素晴らしいフレームワークだと感動しているので、実際使えるのかどうか調査するため、公式ドキュメントやGitHubに上がっているIssueを一つずつ丁寧に読み込んでいこうと思う。(主にcritical issueがないか調査する)

※注意
これは個人的なメモです。

おでんおでん

entに関して参考になりそうな記事を集めてみた。

An entity framework for Go(公式サイト): https://entgo.io/ja/docs/getting-started
100%型安全なgolangORM「ent」を使ってみた: https://future-architect.github.io/articles/20210728a/
GoのORM「ent」の話:https://zenn.dev/masamiki/articles/83a8db3f132fcb1c48f0
ent - An Entity Framework For Go: https://pkg.go.dev/entgo.io/ent#section-readme
Go言語のグラフデータモデル用ORM ent が良かった: https://dev.classmethod.jp/articles/go-gremlin-orm-ent/
GolangのORM「ent」使ってみた: https://www.shoooout.com/posts/go_ent
facebook/ent を使ってみた: https://tennashi.hatenablog.com/entry/2020/09/05/233518
Creating RESTful API with GO Entity Framework: https://medium.com/@louisaldorio/creating-restful-api-with-go-entity-framework-1b24959a74af
facebook の ent を試した。: https://github.com/mattn/entgo-example
domgolonka/ent2proto: https://github.com/domgolonka/ent2proto
rodrigo-brito/ent-orm-poc: https://github.com/rodrigo-brito/ent-orm-poc

おでんおでん

Roadmap for v1 #46
https://github.com/ent/ent/issues/46

List of features/changes we want to finish before releasing an official v1 version:
公式バージョン v1をリリースする前に実現したい機能/変更のリスト:


✅ 2021/11/15時点で完了しているもの↓

  • PostgreSQL support - done
    PostgreSQLのサポート - 完了

  • Eager loading - proposal: eager loading support #91 - done
    Eager loading - 提案: eager loading サポート #91 - 完了

  • User defined IDs - override id column #127 - done
    ユーザー定義のIDなど - id カラムを上書き #127 - 完了

  • Hooks - entc/hooks: initial work for mutations and hooks #377 - done
    フック - entc/hooks: ミューテーションとフックの初期作業 #377 - 完了

  • OSS GraphQL integration - done (expected more work in the near future)
    OSS GraphQL 統合 - 完了 (近い将来に更なる作業が予期されている)

  • Bulk insert - done proposal: Bulk API #236
    バルクインサート - 完了 提案: バルク API #236

  • Privacy layer - done (see entgo.io/docs/privacy)
    プライバシー層 - 完了 (entgo.io/docs/privacy を見てください)


⚡️ 2021/11/15時点での一部が完了しているもの↓

  • User defined types - WIP schema/field: add the option to use dialect specific types #277
    ユーザーが定義できる型 - WIP schema/field: 定義されたSQLの方言固有の型を使うためのオプションを追加 #277

  • Custom Go Type (完了)カスタムできるGoの型

  • Custom Dialect Type(完了)カスタムできる方言(sqlにおける)の型

  • "Other" type(完了)"他の" 型

  • Custom predicates (WIP) カスタムできる述語(sqlにおける)

  • Upsert and batch upsert (方言の定義) (チェックマークは入っているのでおそらくもう少しで完了扱いになると思われる)

  • JSON type predicates (WIP)(チェックマークは入っているがWIPが付いている)

  • Cascading deletion - proposal: cascading deletion support #407
    カスケード削除 - 提案: カスケード削除のサポート #407

  • DDL support(チェックマークが入っている)

  • Application-level support (未完了)
    アプリケーションレベルでのサポート


☔️ 2021/11/15時点で未完了のもの↓

  • Query hooks (interceptors) - Hooks for Read Operations #833
    クエリのフック(インターセプター) - 読み取り操作のフック #833
  • Better migration - offline migration, edge migration ({O2O, O2M} -> M2M).
    Better migration - オフラインマイグレーション、エッジマイグレーション({O2O, O2M} -> M2M)
  • Multi-level caching マルチレベルキャッシュ
  • Cluster support (read replicas)
    クラスターサポート(リードレプリカ)
  • Horizontal sharding 水平シャーディング
  • Edge fields (metadata on edges)
    エッジフィールド(エッジ上のメタデータ)

Please note that this list is changing.
このリストは変更されますのでご注意ください。
(※ちなみにここにまとめているものは2021/11/15時点の情報です)

おでんおでん

ロードマップ内で何か重要そうなコメントだけピックアップしてメモしていく。

おでんおでん

[コメント抜粋]

Exactly. We want to add a cluster-client option (leader and 1 or more read replicas).

クラスタ-クライアントのオプションを追加したい(リーダーと1つ以上のリード・レプリカ)


[自分用メモ]
そもそもクラスタークライアントとはなんだろう、ここら辺を読んでみている
https://docs.microsoft.com/ja-jp/sql/sql-server/failover-clusters/install/install-client-tools-on-a-sql-server-failover-cluster?view=sql-server-ver15

https://nyamadori.hatenablog.com/entry/2017/09/12/103523

おでんおでん

I think the use of read replicas and clustering here means, that ent will support providing separate master and read connection details, but the actual replication should be done by the database cluster.

ここでリードレプリカとクラスタリングが出てくる意味は、
entがマスターとリードの接続情報を別々に提供することをサポートするが、実際のレプリケーションはデータベースクラスタが行うべきだという意味だと思います。

おでんおでん

It would be great to have support for UUIDs as IDs with explicit handling of the ID generation (instead of auto-generating the IDs)

ID生成のUUIDやIDの明示的なハンドリングのためのサポートがあれば素晴らしい(つまりIDが自動生成されるというのではなくて)

We do have plans to add support for custom ID generation

User defined IDs - override id column #127 - done
ユーザー定義のIDなど - id カラムを上書き #127 - 完了
ですでに完了されているっぽい

おでんおでん

Will there be support for MSSql, Redis, Elasticsearch?

No, at least in the foreseeable future. However, as I mentioned above, we have plans to add a public interface for pluggable storage-drivers. So, if someone want to take and maintain it, I'll be happy to help.

ここら辺(MSSql, Redis, Elasticsearch)、当面はサポートされないっぽい

おでんおでん

アノテーション
スキーマアノテーションは、フィールドやエッジなどのスキーマオブジェクトにメタデータを付加し、それを外部テンプレートに注入することができます。 アノテーションは、JSON raw の値にシリアライズ可能なGoの型(struct,map,sliceなど)で、Annotation インターフェイスを実装している必要があります。

Ent内蔵のアノテーションにより、さまざまなストレージドライバー(SQLなど)を設定したり、コード生成の出力を制御したりすることができます。

Edge fields (metadata on edges)
エッジフィールド(エッジ上のメタデータ)

これはすでにアノテーション機能で使えるっぽい?
Edgeにアノテーションをつけているサンプルはないのでまだかも。
https://entgo.io/ja/docs/schema-annotations

おでんおでん

読むべきIssuesを列挙してみる。(2021/11/15時点)
※提案や強化のタグが付いている場合や対応済みでClose待ちのもの、あまり重要でないIssue等は列挙しない

おでんおでん
  • migrate/schema: Confusion of M2M table structure #957 https://github.com/ent/ent/issues/957
    よくわからないM2Mで自己参照しているのが問題で、そのような書き方ができないということなのかなと思った。

  • Foreign key creation fails when IDType is Uint64 #2061 https://github.com/ent/ent/issues/2061
    Uint64でfailしている原因は手元でも再現しようとしましたが特に問題なくジェネレートできたのでよくわからない。

    ※よく読んでみるとあまり重要でない質問のIssueも多かったので、そういうものも除外した。

おでんおでん

ent と gin , openapi とあとインフラにawsを使ってばりばり使えるAPIを作るとこまで行けたので後日記事にまとめる。

このスクラップは2022/02/02にクローズされました