Skip to content

Commit

Permalink
Merge pull request #4 from tonybka/feature/tonybka/update-document
Browse files Browse the repository at this point in the history
Update document
  • Loading branch information
tonybka authored Dec 20, 2022
2 parents 14bc526 + 3ce7622 commit 5b019aa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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/)
3 changes: 3 additions & 0 deletions samples/persistence/account/account_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ 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
}
return nil
}

// FindById query account by it's identity
func (repo *AccountRepository) FindById(id uuid.UUID) (AccountModel, error) {
var dataModel AccountModel

Expand All @@ -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

Expand Down

0 comments on commit 5b019aa

Please sign in to comment.