snippet

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2019 License: MIT Imports: 6 Imported by: 0

README

gorm-snippets

Maintainability Test Coverage

Code snippet generator for GORM. Generates customizable DB helper functions work with GORM. Designed to be used by code generators that generates repository layer code.

Usage

Golang
s, _ := snippet.FindByParam("model.Book", "UUID", "string")

will generate

func findBookByUUID(db *gorm.DB, arg string) (*model.Book, error) {
        if len(arg) == 0 {
                return nil, xerrors.Errorf("UUID must be non-nil.")
        }
        var obj model.Book
        if err := db.Find(&obj, "`uuid` = ?", arg).Error; err != nil {
                return nil, xerrors.Errorf("failed to find model.Book by UUID: %w", err)
        }
        return &obj, nil
}
Command line

TBD

Snippets

  • FindByID
  • FindByParam
  • BatchFindByID
  • BatchFindByParam

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchFindByID

func BatchFindByID(model string) (string, error)

BatchFindByID find objects for every id at once

func BatchFindByParam

func BatchFindByParam(model string, paramName string, paramType string) (string, error)

BatchFindByParam find objects for every id at once

func FindByID

func FindByID(model string) (string, error)

FindByID find object by id

func FindByParam

func FindByParam(model string, paramName string, paramType string) (string, error)

FindByParam find object by param value

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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