storage

package
v0.0.0-...-9e17550 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open() *gorm.DB

Types

type Account

type Account struct {
	// Some notes on GORM conventions:
	// 1. struct name Account corresponds to table name accounts. PetOwner corresponds to pet_owners
	// 2. struct field ID corresponds to table column id and is understood to be the primary key
	// 3. struct fields are CamelCase and table columns are snake_case. CreatedAt == created_at
	// 4. TeamID is understood to refer to struct field Team.ID, or table column teams.id and is a foreign key.
	ID        int
	Name      string
	Email     string
	CreatedAt time.Time
	UpdatedAt time.Time
	TeamID    *int

	// related data is held in this embedded struct
	Team Team
}

Maintain an Account model just for use with the DB to prevent coupling between the service layer and the storage layer. storage.Account (the DB table model) can be converted to an api.Account (the business object) using its toEntity method.

type AccountRepository

type AccountRepository struct {
	// contains filtered or unexported fields
}

storage.AccountRepository represents a MySQL implementation of api.AccountRepository.

func NewAccountRepository

func NewAccountRepository(db *gorm.DB) AccountRepository

func (*AccountRepository) CreateAccount

func (s *AccountRepository) CreateAccount(a *api.Account) error

func (*AccountRepository) DeleteAccount

func (s *AccountRepository) DeleteAccount(id int) error

func (*AccountRepository) GetAccount

func (s *AccountRepository) GetAccount(id int) (*api.Account, error)

func (*AccountRepository) ListAccounts

func (s *AccountRepository) ListAccounts() ([]*api.Account, error)

type Team

type Team struct {
	ID        int
	Name      string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL