Skip to content

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

@OmidHekayati

Description

@OmidHekayati

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions