init
This commit is contained in:
36
local/repository/concert.go
Normal file
36
local/repository/concert.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"rockhu-bot/local/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConcertRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewConcertRepository(db *gorm.DB) *ConcertRepository {
|
||||
return &ConcertRepository{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
// GetAll
|
||||
// Gets all rows from Concert table.
|
||||
//
|
||||
// Args:
|
||||
// context.Context: Application context
|
||||
// Returns:
|
||||
// model.ConcertModel: Concert object from database.
|
||||
func (as ConcertRepository) GetAll(ctx context.Context) *[]model.ConcertModel {
|
||||
db := as.db.WithContext(ctx)
|
||||
ConcertModel := new([]model.ConcertModel)
|
||||
db.Find(&ConcertModel)
|
||||
return ConcertModel
|
||||
}
|
||||
|
||||
func (as ConcertRepository) CreateTransaction() *gorm.DB {
|
||||
return as.db.Begin()
|
||||
}
|
||||
14
local/repository/repository.go
Normal file
14
local/repository/repository.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"go.uber.org/dig"
|
||||
)
|
||||
|
||||
// InitializeRepositories
|
||||
// Initializes Dependency Injection modules for repositories
|
||||
//
|
||||
// Args:
|
||||
// *dig.Container: Dig Container
|
||||
func InitializeRepositories(c *dig.Container) {
|
||||
c.Provide(NewConcertRepository)
|
||||
}
|
||||
Reference in New Issue
Block a user