Categorygithub.com/aklinkert/go-gorm-repository
modulepackage
1.2.0
Repository: https://github.com/aklinkert/go-gorm-repository.git
Documentation: pkg.go.dev

# README

go-gorm-repository

This is a simple repository implementation for GORM providing basic functions to CRUD and query entities as well as transactions and common error handling.

Example

For a complete list of supported methods, please see types.go.

package main

import (
	"github.com/sirupsen/logrus"
	"github.com/aklinkert/go-gorm-repository"
	"gorm.io/gorm"
)

func main() {
	logger := logrus.New()
	db, _ := gorm.Open(_, _)
	
	// third parameter is a list of related entities that should always preload
	repo := gormrepository.NewGormRepository(db, logger, "CreatorUser", "Organization")
	
	instance := &exampleModel{}

	if err := repo.Create(instance); err != nil {
		logger.Fatalf("failed to create cache instance: %v", err)
	}
}

License

Apache 2.0 License

# Functions

NewGormRepository returns a new base repository that implements TransactionRepository.

# Variables

ErrNotFound is a convenience reference for the actual GORM error.

# Interfaces

Repository is a generic DB handler that cares about default error handling.
TransactionRepository extends Repository with modifier functions that accept a transaction.