entrepository

package
v0.0.7-alpha Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Client *ent.Client

Functions

func EntError

func EntError(err error, msg string) error

func New

Types

type BaseRepository

type BaseRepository[E entities.Entity, EE EntityType, EQ EntityQuery[EE], QF QueryFilter] struct {
	Name          string
	Client        *ent.Client
	ConvertFn     func(entEntity *EE) *E
	ByIDFn        func(ctx context.Context, client *ent.Client, id int) (*EE, error)
	DeleteByIDFn  func(ctx context.Context, client *ent.Client, id int) error
	CreateFn      func(ctx context.Context, client *ent.Client, data *E) (*EE, error)
	UpdateFn      func(ctx context.Context, client *ent.Client, data *E) (*EE, error)
	FindFn        func(ctx context.Context, query EQ, filters ...QF) ([]*EE, error)
	QueryFilterFn func(client *ent.Client, filters ...QF) EQ
}

func (*BaseRepository[E, EE, EQ, QF]) All

func (b *BaseRepository[E, EE, EQ, QF]) All(ctx context.Context) ([]*E, error)

func (*BaseRepository[E, EE, EQ, QF]) ByID

func (b *BaseRepository[E, EE, EQ, QF]) ByID(ctx context.Context, id int) (*E, error)

func (*BaseRepository[E, EE, EQ, QF]) Count

func (b *BaseRepository[E, EE, EQ, QF]) Count(ctx context.Context, filters ...QF) (int, error)

func (*BaseRepository[E, EE, EQ, QF]) Create

func (b *BaseRepository[E, EE, EQ, QF]) Create(ctx context.Context, data *E) (*E, error)

func (*BaseRepository[E, EE, EQ, QF]) DeleteByID

func (b *BaseRepository[E, EE, EQ, QF]) DeleteByID(ctx context.Context, id int) error

func (*BaseRepository[E, EE, EQ, QF]) Find

func (b *BaseRepository[E, EE, EQ, QF]) Find(ctx context.Context, filters ...QF) ([]*E, error)

func (*BaseRepository[E, EE, EQ, QF]) Paginate

func (b *BaseRepository[E, EE, EQ, QF]) Paginate(ctx context.Context, filters ...QF) (*entities.Paginate[E], error)

func (*BaseRepository[E, EE, EQ, QF]) Update

func (b *BaseRepository[E, EE, EQ, QF]) Update(ctx context.Context, data *E) (*E, error)

type CommentRepository

type CommentRepository struct {
	*BaseRepository[e.Comment, ent.Comment, *ent.CommentQuery, *e.CommentFilter]
}

func CreateCommentRepository

func CreateCommentRepository(client *ent.Client) *CommentRepository

func (*CommentRepository) FindWithPost

func (c *CommentRepository) FindWithPost(ctx context.Context, filters ...*e.CommentFilter) ([]*e.Comment, error)

func (*CommentRepository) PaginateWithPost

func (c *CommentRepository) PaginateWithPost(ctx context.Context, filters ...*e.CommentFilter) (*e.Paginate[e.Comment], error)

type Config

type Config struct {
	DB_DSN    string
	DB_DRIVER string
}

type EntityType

type EntityType interface {
	ent.Comment | ent.File | ent.Permission | ent.Post | ent.Page | ent.Role | ent.Setting | ent.Topic | ent.User
}

type FileRepository

type FileRepository = BaseRepository[e.File, ent.File, *ent.FileQuery, *e.FileFilter]

func CreateFileRepository

func CreateFileRepository(client *ent.Client) *FileRepository

type PageRepository

type PageRepository struct {
	*BaseRepository[e.Page, ent.Page, *ent.PageQuery, *e.PageFilter]
}

func CreatePageRepository

func CreatePageRepository(client *ent.Client) *PageRepository

func (*PageRepository) PublishedPageBySlug

func (p *PageRepository) PublishedPageBySlug(ctx context.Context, slug string) (*entities.Page, error)

type PermissionRepository

func CreatePermissionRepository

func CreatePermissionRepository(client *ent.Client) *PermissionRepository

type PostRepository

type PostRepository struct {
	*BaseRepository[e.Post, ent.Post, *ent.PostQuery, *e.PostFilter]
}

func CreatePostRepository

func CreatePostRepository(client *ent.Client) *PostRepository

func (*PostRepository) Approve

func (p *PostRepository) Approve(ctx context.Context, id int) (err error)

func (*PostRepository) IncreaseViewCount

func (p *PostRepository) IncreaseViewCount(ctx context.Context, id int, views int64) (err error)

func (*PostRepository) PublishedPostByID

func (p *PostRepository) PublishedPostByID(ctx context.Context, id int) (*entities.Post, error)

type QueryFilter

type QueryFilter interface {
	GetSearch() string
	GetPage() int
	GetLimit() int
	GetSorts() []*entities.Sort
	GetIgnoreUrlParams() []string
	GetExcludeIDs() []int
	Base() string
}

type Repository

type Repository struct {
	Client *ent.Client
}

type RoleRepository

type RoleRepository struct {
	*BaseRepository[e.Role, ent.Role, *ent.RoleQuery, *e.RoleFilter]
}

func CreateRoleRepository

func CreateRoleRepository(client *ent.Client) *RoleRepository

func (*RoleRepository) ByName

func (p *RoleRepository) ByName(ctx context.Context, name string) (*e.Role, error)

func (*RoleRepository) SetPermissions

func (p *RoleRepository) SetPermissions(ctx context.Context, id int, permissions []*e.PermissionValue) error

type SettingRepository

type SettingRepository struct {
	*Repository
}

func (*SettingRepository) All

func (*SettingRepository) Save

func (ur *SettingRepository) Save(ctx context.Context, settings []*entities.Setting) error

type TopicRepository

type TopicRepository struct {
	*BaseRepository[e.Topic, ent.Topic, *ent.TopicQuery, *e.TopicFilter]
}

func CreateTopicRepository

func CreateTopicRepository(client *ent.Client) *TopicRepository

func (*TopicRepository) ByName

func (c *TopicRepository) ByName(ctx context.Context, name string) (*e.Topic, error)

type UserRepository

type UserRepository struct {
	*BaseRepository[e.User, ent.User, *ent.UserQuery, *e.UserFilter]
}

func CreateUserRepository

func CreateUserRepository(client *ent.Client) *UserRepository

func (*UserRepository) ByProvider

func (u *UserRepository) ByProvider(ctx context.Context, providerName, providerId string) (*entities.User, error)

func (*UserRepository) ByUsername

func (u *UserRepository) ByUsername(ctx context.Context, username string) (*entities.User, error)

func (*UserRepository) ByUsernameOrEmail

func (u *UserRepository) ByUsernameOrEmail(ctx context.Context, username, email string) ([]*entities.User, error)

func (*UserRepository) CreateIfNotExistsByProvider

func (ur *UserRepository) CreateIfNotExistsByProvider(ctx context.Context, userData *entities.User) (*entities.User, error)

func (*UserRepository) Setting

func (ur *UserRepository) Setting(ctx context.Context, id int, userData *entities.SettingMutation) (*entities.User, error)

Directories

Path Synopsis
ent

Jump to

Keyboard shortcuts

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