db

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetCat           GetName       = "GetCat"
	QueryCat         QueryName     = "QueryCat"
	AddCat           AddName       = "AddCat"
	UpdateCat        UpdateName    = "UpdateCat"
	DeleteCat        DeleteName    = "DeleteCat"
	GetCompany       GetName       = "GetCompany"
	QueryCompany     QueryName     = "QueryCompany"
	AddCompany       AddName       = "AddCompany"
	UpdateCompany    UpdateName    = "UpdateCompany"
	DeleteCompany    DeleteName    = "DeleteCompany"
	GetSmartPhone    GetName       = "GetSmartPhone"
	QuerySmartPhone  QueryName     = "QuerySmartPhone"
	AddSmartPhone    AddName       = "AddSmartPhone"
	UpdateSmartPhone UpdateName    = "UpdateSmartPhone"
	DeleteSmartPhone DeleteName    = "DeleteSmartPhone"
	AddUser2Todos    Many2ManyName = "AddUser2Todos"
	GetTodo          GetName       = "GetTodo"
	QueryTodo        QueryName     = "QueryTodo"
	AddTodo          AddName       = "AddTodo"
	UpdateTodo       UpdateName    = "UpdateTodo"
	DeleteTodo       DeleteName    = "DeleteTodo"
	GetUser          GetName       = "GetUser"
	QueryUser        QueryName     = "QueryUser"
	AddUser          AddName       = "AddUser"
	UpdateUser       UpdateName    = "UpdateUser"
	DeleteUser       DeleteName    = "DeleteUser"
)

Variables

This section is empty.

Functions

func AddAddHook

func AddAddHook[M AutoGqlHookM, I AutoGqlHookI, AP AutoGqlHookAP](db *AutoGqlDB, name AddName, implementation AutoGqlHookAdd[M, I, AP])

Add a addHook useable for

  • AddCat
  • AddCompany
  • AddSmartPhone
  • AddTodo
  • AddUser

func AddDeleteHook

func AddDeleteHook[F AutoGqlHookF, DP AutoGqlHookDP](db *AutoGqlDB, name DeleteName, implementation AutoGqlHookDelete[F, DP])

Add a updateHook useable for

  • DeleteCat
  • DeleteCompany
  • DeleteSmartPhone
  • DeleteTodo
  • DeleteUser

func AddGetHook

func AddGetHook[T AutoGqlHookM, I any](db *AutoGqlDB, name GetName, implementation AutoGqlHookGet[T, I])

Add a getHook useable for

  • GetCat
  • GetCompany
  • GetSmartPhone
  • GetTodo
  • GetUser

func AddMany2ManyHook

func AddMany2ManyHook[U AutoGqlHookM2M, UP AutoGqlHookUP](db *AutoGqlDB, name Many2ManyName, implementation AutoGqlHookMany2Many[U, UP])

Add a Many2Many Hook useable for

  • AddUser2Todos

func AddQueryHook

func AddQueryHook[M AutoGqlHookM, F AutoGqlHookF, O AutoGqlHookQueryO](db *AutoGqlDB, name QueryName, implementation AutoGqlHookQuery[M, F, O])

Add a queryHook useable for

  • QueryCat
  • QueryCompany
  • QuerySmartPhone
  • QueryTodo
  • QueryUser

func AddUpdateHook

func AddUpdateHook[M AutoGqlHookM, U AutoGqlHookU, UP AutoGqlHookUP](db *AutoGqlDB, name UpdateName, implementation AutoGqlHookUpdate[U, UP])

Add a updateHook useable for

  • UpdateCat
  • UpdateCompany
  • UpdateSmartPhone
  • UpdateTodo
  • UpdateUser

Types

type AddName

type AddName string

type AutoGqlDB

type AutoGqlDB struct {
	Db    *gorm.DB
	Hooks map[string]any
}

func NewAutoGqlDB

func NewAutoGqlDB(db *gorm.DB) AutoGqlDB

Create a new AutoGqlDB

func (*AutoGqlDB) Init

func (db *AutoGqlDB) Init()

execute Gorm AutoMigrate with all @SQL Graphql Types

type AutoGqlHookAdd

type AutoGqlHookAdd[obj AutoGqlHookM, input AutoGqlHookI, res AutoGqlHookAP] interface {
	Received(ctx context.Context, dbHelper *AutoGqlDB, input []*input) (*gorm.DB, []*input, error) // Direct after Resolver is call
	BeforeCallDb(ctx context.Context, db *gorm.DB, data []obj) (*gorm.DB, []obj, error)            // Direct before call Database
	BeforeReturn(ctx context.Context, db *gorm.DB, data []obj, res *res) (*res, error)             // After database call with resultset from database
}

Interface description of a add Hook Simple you can use DefaultAddHook and only implement the hooks you need:

type MyAddHook struct {
   DefaultAddHook[model.Todo, model.TodoInput, model.AddTodoPayload]
}
func (m MyAddHook) BeforeCallDb(ctx context.Context, db *gorm.DB, data []model.Todo) (*gorm.DB, []model.Todo, error) {
   //do some stuff
   return db, data, nil
}

type AutoGqlHookDelete

type AutoGqlHookDelete[input AutoGqlHookF, res AutoGqlHookDP] interface {
	Received(ctx context.Context, dbHelper *AutoGqlDB, input *input) (*gorm.DB, input, error) // Direct after Resolver is call
	BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, error)                          // Direct before call Database
	BeforeReturn(ctx context.Context, db *gorm.DB, res *res) (*res, error)                    // After database call with resultset from database
}

Interface description of a delete Hook Simple you can use DefaultDeleteHook and only implement the hooks you need:

type MyM2mHook struct {
   DefaultDeleteHook[model.TodoFiltersInput, model.DeleteTodoPayload]
}
func (m MyM2mHook) BeforeCallDb(ctx context.Context, db *gorm.DB, input model.TodoFiltersInput) (*gorm.DB, model.TodoFiltersInput, error) {
   //do some stuff
   return db, input, nil
}

type AutoGqlHookGet

type AutoGqlHookGet[obj AutoGqlHookM, identifier any] interface {
	Received(ctx context.Context, dbHelper *AutoGqlDB, id ...identifier) (*gorm.DB, error) // Direct after Resolver is call
	BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, error)                       // Direct before call Database
	AfterCallDb(ctx context.Context, data *obj) (*obj, error)                              // After database call with resultset from database
	BeforeReturn(ctx context.Context, data *obj, db *gorm.DB) (*obj, error)                // short before return the data
}

Interface description of a getHook Simple you can use DefaultGetHook and only implement the hooks you need:

type MyGetHook struct {
   DefaultGetHook[model.Todo, model.TodoInput, model.AddTodoPayload]
}
func (m MyGetHook) BeforeCallDb(ctx context.Context, db *gorm.DB, data []model.Todo) (*gorm.DB, []model.Todo, error) {
   //do some stuff
   return db, data, nil
}

type AutoGqlHookI

Input Hooks

type AutoGqlHookM

type AutoGqlHookM interface {
	model.Cat | model.Company | model.SmartPhone | model.Todo | model.User
}

Modelhooks

type AutoGqlHookM2M

type AutoGqlHookM2M interface {
	model.UserRef2TodosInput
}

Many2Many Hooks

type AutoGqlHookMany2Many

type AutoGqlHookMany2Many[input AutoGqlHookM2M, res AutoGqlHookUP] interface {
	Received(ctx context.Context, dbHelper *AutoGqlDB, input *input) (*gorm.DB, input, error) // Direct after Resolver is call
	BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, error)                          // Direct before call Database
	BeforeReturn(ctx context.Context, db *gorm.DB, res *res) (*res, error)                    // After database call with resultset from database
}

Interface description of a many2many Hook Simple you can use DefaultMany2ManyHook and only implement the hooks you need:

type MyM2mHook struct {
   DefaultMany2ManyHook[model.UserRef2TodosInput, model.UpdateTodoPayload]
}
func (m MyM2mHook) BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, error) {
   //do some stuff
   return db, nil
}

type AutoGqlHookQuery

type AutoGqlHookQuery[obj AutoGqlHookM, filter AutoGqlHookF, order AutoGqlHookQueryO] interface {
	Received(ctx context.Context, dbHelper *AutoGqlDB, filter *filter, order *order, first, offset *int) (*gorm.DB, *filter, *order, *int, *int, error) // Direct after Resolver is call
	BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, error)                                                                                    // Direct before call Database
	AfterCallDb(ctx context.Context, data []*obj) ([]*obj, error)                                                                                       // After database call with resultset from database
	BeforeReturn(ctx context.Context, data []*obj, db *gorm.DB) ([]*obj, error)                                                                         // short before return the data
}

Interface description of a query Hook Simple you can use DefaultQueryHook and only implement the hooks you need:

type MyQueryHook struct {
   DefaultQueryHook[model.Todo, model.TodoFiltersInput, model.TodoOrder]
}
func (m MyQueryHook) BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, []model.Todo, error) {
   //do some stuff
   return db, nil
}

type AutoGqlHookQueryO

type AutoGqlHookQueryO interface {
	model.CatOrder | model.CompanyOrder | model.SmartPhoneOrder | model.TodoOrder | model.UserOrder
}

Order Hooks

type AutoGqlHookUpdate

type AutoGqlHookUpdate[input AutoGqlHookU, res AutoGqlHookUP] interface {
	Received(ctx context.Context, dbHelper *AutoGqlDB, input *input) (*gorm.DB, input, error)                             // Direct after Resolver is call
	BeforeCallDb(ctx context.Context, db *gorm.DB, data map[string]interface{}) (*gorm.DB, map[string]interface{}, error) // Direct before call Database
	BeforeReturn(ctx context.Context, db *gorm.DB, res *res) (*res, error)                                                // After database call with resultset from database
}

Interface description of a update Hook Simple you can use DefaultUpdateHook and only implement the hooks you need:

type MyUpdateHook struct {
   DefaultUpdateHook[model.TodoInput, model.UpdateTodoPayload]
}
func (m MyUpdateHook) BeforeCallDb(ctx context.Context, db *gorm.DB, data map[string]interface{}) (*gorm.DB,  map[string]interface{}, error) {
   //do some stuff
   return db, data, nil
}

type DefaultAddHook

type DefaultAddHook[obj AutoGqlHookM, input AutoGqlHookI, res AutoGqlHookAP] struct{}

Default add hook implementation Simple you can use DefaultAddHook and only implement the hooks you need:

type MyAddHook struct {
   DefaultAddHook[model.Todo, model.TodoInput, model.AddTodoPayload]
}
func (m MyAddHook) BeforeCallDb(ctx context.Context, db *gorm.DB, data []model.Todo) (*gorm.DB, []model.Todo, error) {
   //do some stuff
   return db, data, nil
}

func (DefaultAddHook[obj, inputType, resType]) BeforeCallDb

func (d DefaultAddHook[obj, inputType, resType]) BeforeCallDb(ctx context.Context, db *gorm.DB, data []obj) (*gorm.DB, []obj, error)

Direct before call Database

func (DefaultAddHook[obj, inputType, resType]) BeforeReturn

func (d DefaultAddHook[obj, inputType, resType]) BeforeReturn(ctx context.Context, db *gorm.DB, data []obj, res *resType) (*resType, error)

After database call with resultset from database

func (DefaultAddHook[obj, inputType, resType]) Received

func (d DefaultAddHook[obj, inputType, resType]) Received(ctx context.Context, dbHelper *AutoGqlDB, input []*inputType) (*gorm.DB, []*inputType, error)

Direct after Resolver is call

type DefaultDeleteHook

type DefaultDeleteHook[input AutoGqlHookF, res AutoGqlHookDP] struct{}

Default delete hook implementation Simple you can use DefaultDeleteHook and only implement the hooks you need:

type MyM2mHook struct {
   DefaultDeleteHook[model.TodoFiltersInput, model.DeleteTodoPayload]
}
func (m MyM2mHook) BeforeCallDb(ctx context.Context, db *gorm.DB, input model.TodoFiltersInput) (*gorm.DB, model.TodoFiltersInput, error) {
   //do some stuff
   return db, input, nil
}

func (DefaultDeleteHook[inputType, resType]) BeforeCallDb

func (d DefaultDeleteHook[inputType, resType]) BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, error)

Direct before call Database

func (DefaultDeleteHook[inputType, resType]) BeforeReturn

func (d DefaultDeleteHook[inputType, resType]) BeforeReturn(ctx context.Context, db *gorm.DB, res *resType) (*resType, error)

After database call with resultset from database

func (DefaultDeleteHook[inputType, resType]) Received

func (d DefaultDeleteHook[inputType, resType]) Received(ctx context.Context, dbHelper *AutoGqlDB, input *inputType) (*gorm.DB, inputType, error)

Direct after Resolver is call

type DefaultGetHook

type DefaultGetHook[obj AutoGqlHookM, identifier any] struct{}

Default get hook implementation Simple you can use and only implement the hooks you need:

type MyGetHook struct {
   DefaultGetHook[model.Todo, int64]
}
func (m MyGetHook) BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, []model.Todo, error) {
   //do some stuff
   return db, data, nil
}

func (DefaultGetHook[obj, identifier]) AfterCallDb

func (d DefaultGetHook[obj, identifier]) AfterCallDb(ctx context.Context, data *obj) (*obj, error)

After database call with resultset from database

func (DefaultGetHook[obj, identifier]) BeforeCallDb

func (d DefaultGetHook[obj, identifier]) BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, error)

Direct before call Database

func (DefaultGetHook[obj, identifier]) BeforeReturn

func (d DefaultGetHook[obj, identifier]) BeforeReturn(ctx context.Context, data *obj, db *gorm.DB) (*obj, error)

short before return the data

func (DefaultGetHook[obj, identifier]) Received

func (d DefaultGetHook[obj, identifier]) Received(ctx context.Context, dbHelper *AutoGqlDB, id ...identifier) (*gorm.DB, error)

Direct after Resolver is call

type DefaultMany2ManyHook

type DefaultMany2ManyHook[input AutoGqlHookM2M, res AutoGqlHookUP] struct{}

Default many2many hook implementation Simple you can use DefaultMany2ManyHook and only implement the hooks you need:

type MyM2mHook struct {
   DefaultMany2ManyHook[model.UserRef2TodosInput, model.UpdateTodoPayload]
}
func (m MyM2mHook) BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, error) {
   //do some stuff
   return db, nil
}

func (DefaultMany2ManyHook[inputType, resType]) BeforeCallDb

func (d DefaultMany2ManyHook[inputType, resType]) BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, error)

Direct before call Database

func (DefaultMany2ManyHook[inputType, resType]) BeforeReturn

func (d DefaultMany2ManyHook[inputType, resType]) BeforeReturn(ctx context.Context, db *gorm.DB, res *resType) (*resType, error)

After database call with resultset from database

func (DefaultMany2ManyHook[inputType, resType]) Received

func (d DefaultMany2ManyHook[inputType, resType]) Received(ctx context.Context, dbHelper *AutoGqlDB, input *inputType) (*gorm.DB, inputType, error)

Direct after Resolver is call

type DefaultQueryHook

type DefaultQueryHook[obj AutoGqlHookM, filter AutoGqlHookF, order AutoGqlHookQueryO] struct{}

Default query hook implementation Simple you can use DefaultQueryHook and only implement the hooks you need:

type MyQueryHook struct {
   DefaultQueryHook[model.Todo, model.TodoFiltersInput, model.TodoOrder]
}
func (m MyQueryHook) BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, []model.Todo, error) {
   //do some stuff
   return db, nil
}

func (DefaultQueryHook[obj, filter, order]) AfterCallDb

func (d DefaultQueryHook[obj, filter, order]) AfterCallDb(ctx context.Context, data []*obj) ([]*obj, error)

After database call with resultset from database

func (DefaultQueryHook[obj, filter, order]) BeforeCallDb

func (d DefaultQueryHook[obj, filter, order]) BeforeCallDb(ctx context.Context, db *gorm.DB) (*gorm.DB, error)

Direct before call Database

func (DefaultQueryHook[obj, filter, order]) BeforeReturn

func (d DefaultQueryHook[obj, filter, order]) BeforeReturn(ctx context.Context, data []*obj, db *gorm.DB) ([]*obj, error)

short before return the data

func (DefaultQueryHook[obj, filterType, orderType]) Received

func (d DefaultQueryHook[obj, filterType, orderType]) Received(ctx context.Context, dbHelper *AutoGqlDB, filter *filterType, order *orderType, first, offset *int) (*gorm.DB, *filterType, *orderType, *int, *int, error)

Direct after Resolver is call

type DefaultUpdateHook

type DefaultUpdateHook[input AutoGqlHookU, res AutoGqlHookUP] struct{}

Default update hook implementation Simple you can use DefaultUpdateHook and only implement the hooks you need:

type MyUpdateHook struct {
   DefaultUpdateHook[model.TodoInput, model.UpdateTodoPayload]
}
func (m MyUpdateHook) BeforeCallDb(ctx context.Context, db *gorm.DB, data map[string]interface{}) (*gorm.DB,  map[string]interface{}, error) {
   //do some stuff
   return db, data, nil
}

func (DefaultUpdateHook[inputType, resType]) BeforeCallDb

func (d DefaultUpdateHook[inputType, resType]) BeforeCallDb(ctx context.Context, db *gorm.DB, data map[string]interface{}) (*gorm.DB, map[string]interface{}, error)

Direct before call Database

func (DefaultUpdateHook[inputType, resType]) BeforeReturn

func (d DefaultUpdateHook[inputType, resType]) BeforeReturn(ctx context.Context, db *gorm.DB, res *resType) (*resType, error)

After database call with resultset from database

func (DefaultUpdateHook[inputType, resType]) Received

func (d DefaultUpdateHook[inputType, resType]) Received(ctx context.Context, dbHelper *AutoGqlDB, input *inputType) (*gorm.DB, inputType, error)

Direct after Resolver is call

type DeleteName

type DeleteName string

type GetName

type GetName string

type Many2ManyName

type Many2ManyName string

type QueryName

type QueryName string

type UpdateName

type UpdateName string

Jump to

Keyboard shortcuts

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