Skip to content

💾 Generic golang repository interface and implementations

Notifications You must be signed in to change notification settings

vicent-dev/generic-repository

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

💾 Generic golang repository interface and implementations

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages