Categorygithub.com/vicent-dev/generic-repository
repository
1.1.1
Repository: https://github.com/vicent-dev/generic-repository.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

Go repository

About

Golang database access using generics and implementation with gorm.

Interface exposed:

type Repository[T Entity] interface {
    Find(id int) (*T, error)
    FindByWithRelations(fs ...Field) ([]T, error)
    FindWithRelations(id int) (*T, error)
    FindBy(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.