diff --git a/README.md b/README.md index b2b56e9..5b8f0d6 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,27 @@ Fundamental elements of DDD implementation in Golang microservice # Components ## Domain Layer -- Entity -- Value Object -- Domain Event +### Entity +- Mutable, has identity +### Value Object +- Immutable, no identity +### Domain Event +- Utility for communication between bounded contexts, sub-domains, and between microservices ## Persistence Layer - Data Model -- Repository \ No newline at end of file +- Repository + + +# Q&A +## Why UUIDv1 for entity's identity? +### Reasons (short) +- Need to have random, unique identity values for entities +- To decouple domain layer from persistence layer, we should not use table row's id for entity's identity +- MySQL support storing UUIDv1 as BINARY(16) in database which saves storage space + +### References +- [Making UUIDs More Performant in MySQL](https://emmer.dev/blog/making-uuids-more-performant-in-mysql/) +- [Storing UUID Values in MySQL Tables](https://dev.mysql.com/blog-archive/storing-uuid-values-in-mysql-tables/) +- [GUID/UUID Performance Breakthrough](http://mysql.rjweb.org/doc.php/uuid) +- [Storing UUID Values in MySQL](https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/) \ No newline at end of file diff --git a/samples/persistence/account/account_repository.go b/samples/persistence/account/account_repository.go index 32c3076..19eff7d 100644 --- a/samples/persistence/account/account_repository.go +++ b/samples/persistence/account/account_repository.go @@ -14,6 +14,7 @@ func NewAccountRepository(db *gorm.DB) *AccountRepository { return &AccountRepository{db} } +// Create creates new account func (repo *AccountRepository) Create(dataModel AccountModel) error { if result := repo.db.Create(&dataModel); result.Error != nil { return result.Error @@ -21,6 +22,7 @@ func (repo *AccountRepository) Create(dataModel AccountModel) error { return nil } +// FindById query account by it's identity func (repo *AccountRepository) FindById(id uuid.UUID) (AccountModel, error) { var dataModel AccountModel @@ -31,6 +33,7 @@ func (repo *AccountRepository) FindById(id uuid.UUID) (AccountModel, error) { return dataModel, nil } +// GetAll returns all accounts in the table func (repo *AccountRepository) GetAll() ([]AccountModel, error) { var dataModels []AccountModel