Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 939 Bytes

Readme.md

File metadata and controls

45 lines (32 loc) · 939 Bytes

Go repository

About

Golang database access using generics and implementation with gorm.

Interface exposed:

type Repository[T Entity] interface {
    Find(id string) (*T, error)
    FindWithRelations(id string) (*T, error)
    FindBy(fs ...Field) ([]*T, error)
    FindPaginated(pageSize, page int) (*Pagination, error)
    FindByWithRelations(fs ...Field) ([]*T, error)
    FindFirstBy(fs ...Field) (*T, error)
    CreateBulk(ts []T) error
    Create(t *T) error
    Update(t *T, fs ...Field) error
    Delete(t *T) error
}

Install

go get github.com/vicent-dev/generic-repository

Usage

Call of repository for an MyEntity entity using Gorm:

import (
    repository "github.com/vicent-dev/generic-repository"
)

r := repository.GetGormRepository[MyEntity](db)

This function will return a repository of the struct type. Prepared for having only one instance in memory by struct type.