update

package
v0.0.0-...-7eceb3a Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2017 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewThingUpdateHandler

func NewThingUpdateHandler(db *sqlx.DB) gin.HandlerFunc

NewThingUpdateHandler will return a handler for ThingUpdateRequests.

The handler assumes that the ThingUpdateRequest will be PATCHed using JSON.

Types

type SQLThingUpdater

type SQLThingUpdater struct {
	// contains filtered or unexported fields
}

SQLThingUpdater implements a SQL based updater

func (*SQLThingUpdater) DeleteByID

func (r *SQLThingUpdater) DeleteByID(ID int64) error

DeleteByID generates a Delete update and executes it

func (*SQLThingUpdater) Update

func (r *SQLThingUpdater) Update(updateRequest ThingUpdateRequest) error

Update converts a ThingUpdateRequest in to SQL and executes it

type ThingField

type ThingField int

ThingField is a field within the Thing struct that is able to be updated

const (
	ThingColor ThingField = iota
	ThingDescription
	ThingLength
	ThingHeight
)

Enum'd for helpfulness

func (ThingField) DbFieldName

func (s ThingField) DbFieldName() string

DbFieldName returns the name of the field to use in the SQL query

func (ThingField) MarshalText

func (s ThingField) MarshalText() ([]byte, error)

MarshalText implements https://golang.org/pkg/encoding/#TextMarshaler

func (*ThingField) UnmarshalText

func (s *ThingField) UnmarshalText(b []byte) error

UnmarshalText implements https://golang.org/pkg/encoding/#TextUnmarshaler

type ThingUpdateRequest

type ThingUpdateRequest struct {
	ID      int64                      `json:"id"`
	Updates map[ThingField]interface{} `json:"updates"`
}

ThingUpdateRequest defines a set of parameters for updating Thing. It can be serialized and passed between services as JSON, or used to generate a SQL statement.

func (*ThingUpdateRequest) AddUpdate

func (ur *ThingUpdateRequest) AddUpdate(field ThingField, value interface{})

AddUpdate implements updater.UpdateRequest interface

func (*ThingUpdateRequest) GetID

func (ur *ThingUpdateRequest) GetID() int64

GetID implements updater.UpdateRequest interface

func (*ThingUpdateRequest) GetTableName

func (ur *ThingUpdateRequest) GetTableName() string

GetTableName implements updater.UpdateRequest interface

func (*ThingUpdateRequest) GetUpdates

func (ur *ThingUpdateRequest) GetUpdates() map[string]interface{}

GetUpdates implements updater.UpdateRequest interface

func (ThingUpdateRequest) MarshalBinary

func (ur ThingUpdateRequest) MarshalBinary() ([]byte, error)

MarshalBinary implements https://golang.org/pkg/encoding/#BinaryMarshaler

func (ThingUpdateRequest) MarshalText

func (ur ThingUpdateRequest) MarshalText() ([]byte, error)

MarshalText implements https://golang.org/pkg/encoding/#TextMarshaler

func (*ThingUpdateRequest) UnmarshalBinary

func (ur *ThingUpdateRequest) UnmarshalBinary(b []byte) error

UnmarshalBinary implements https://golang.org/pkg/encoding/#BinaryUnmarshaler

func (*ThingUpdateRequest) UnmarshalText

func (ur *ThingUpdateRequest) UnmarshalText(b []byte) error

UnmarshalText implements https://golang.org/pkg/encoding/#TextUnmarshaler

type ThingUpdater

type ThingUpdater interface {
	Update(updateRequest ThingUpdateRequest) error
	DeleteByID(ID int64) error
}

ThingUpdater is the interface

func NewSQLThingUpdater

func NewSQLThingUpdater(db *sqlx.DB) ThingUpdater

NewSQLThingUpdater returns a configured updater

Jump to

Keyboard shortcuts

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