gocrudify

package module
v0.0.0-...-0f8e30a Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: MIT Imports: 14 Imported by: 0

README

GoCrudify

GoCrudify is a library meant to easily expose CRUD operations through REST APIs that encodes the payloads in JSON format for any Go struct.

Installation

Be sure to have Go installed. GoCrudify has been developed on Go 1.19, so no retrocompatibility is ensured for now. In the future, versions older than the latest will be supported.

Simply run:

go get github.com/Kavuti/gocrudify

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCrudHandler

func NewCrudHandler[T Entity](tableName string, db *sqlx.DB) *crudHandler[T]

func NewCrudRepository

func NewCrudRepository[T Entity](tableName string, idFieldInfo *CrudFieldValue, nonIdFields []CrudFieldValue) *crudRepository[T]

func NewCrudService

func NewCrudService[T Entity](db *sqlx.DB, tableName string, idFieldInfo *CrudFieldValue, nonIdFields []CrudFieldValue) *crudService[T]

func ParseFilter

func ParseFilter(payload map[string]interface{}, nonIdFields []CrudFieldValue) sq.Sqlizer

Types

type CrudFieldValue

type CrudFieldValue struct {
	Name     string
	DbName   string
	JsonName string
	Type     reflect.Type
}

func GetIdField

func GetIdField[T Entity]() *CrudFieldValue

func GetNonIdFields

func GetNonIdFields[T Entity]() []CrudFieldValue

type Entity

type Entity interface {
	render.Renderer
	ValidateCreation(db *sqlx.Tx) error
	ValidateUpdate(db *sqlx.Tx) error
	ValidateDeletion(db *sqlx.Tx) error
}

type Handler

type Handler interface {
	Search(w http.ResponseWriter, r *http.Request)
	Get(w http.ResponseWriter, r *http.Request)
	Create(w http.ResponseWriter, r *http.Request)
	Update(w http.ResponseWriter, r *http.Request)
	Delete(w http.ResponseWriter, r *http.Request)
	Routes() chi.Router
}

type Repository

type Repository[T Entity] interface {
	Search(ctx context.Context, filter map[string]interface{}) []T
	Get(ctx context.Context, id string) *T
	Create(ctx context.Context, entity *T) *T
	Update(ctx context.Context, id string, entity *T) *T
	Delete(ctx context.Context, id string)
}

type Service

type Service[T Entity] interface {
	Search(ctx context.Context, filter map[string]interface{}) []T
	Get(ctx context.Context, id string) *T
	Create(ctx context.Context, entity *T) *T
	Update(ctx context.Context, entity *T) *T
	Delete(ctx context.Context, id string)
}

Jump to

Keyboard shortcuts

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