Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[modules/storage] Implement interface to SQL service #8

Open
OmidHekayati opened this issue May 16, 2023 · 0 comments
Open

[modules/storage] Implement interface to SQL service #8

OmidHekayati opened this issue May 16, 2023 · 0 comments

Comments

@OmidHekayati
Copy link
Member

Hints:

  • At least need three services: generate mysql.sql, generate mysql.go, and generate volatile-memory.go files.
  • Input example:
// Storage_Fields indicates the domain record data fields.
type Storage_Fields interface {
	RequestID() UserRequestUUID //
	DomainID() uint64           // Domain MediaTypeID e.g. product, content, ... domain
	ServiceID() uint64          //
	UserID() protocol.UserID    // user domain
	UserConnectionID() [16]byte // Store to remember which request belongs to which Connection/AppInstance.
	Time() protocol.Time // Request time or save Time of the request not the created record by this record.
}

// Storage_Services indicates the domain storage layer services.
type Storage_Services interface {
	Save(sf Storage_Fields) (err protocol.Error)

	Get(requestID UserRequestUUID, vo protocol.VersionOffset) (sf Storage_Fields, err protocol.Error)

	FindByDomain(domainID uint64, offset, limit uint64) (requestIDs []UserRequestUUID, err protocol.Error)
	FindByUser(userID [16]byte, offset, limit uint64) (requestIDs []UserRequestUUID, err protocol.Error)
}
  • Develop to easily add support for multiple storage engines (other than SQL based) in future
  • generate MySQL, Postgres, ... optimized SQL not general SQL codes
  • Use SQL procedure for queries not send a query in each request.

Problems need to fix in comparison to other modules:

  • As long as it is possible logic must be in compile-time not runtime.
  • Respect object life cycle and abstraction patterns. e.g. Initiliaze of each domain storage must take place in that domain, not the main of the application.
  • All existing modules in the Go ecosystem force the developer to write the storage layer handly! we need to write efficient codes for the storage layer by given storage interfaces.
    It means we don't need these fancy things:
users, err := models.Users(
  Select("id", "name"),
  InnerJoin("credit_cards c on c.user_id = users.id"),
  Where("age > ?", 30),
  AndIn("c.kind in ?", "visa", "mastercard"),
  Or("email like ?", `%aol.com%`),
  GroupBy("id", "name"),
  Having("count(c.id) > ?", 2),
  Limit(5),
  Offset(6),
).All(ctx, db)

other modules:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant