SqlMarshall

package module
v0.0.0-...-d942904 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2017 License: BSD-3-Clause Imports: 11 Imported by: 0

README

go-sqlmarshall

Marshall/UnMarshall routines for using sqlx with GO

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadTableName = errors.New("The table name inputted does not contain legal characters")

ErrBadTableName used in case of illegal characters in the table definition in GetTableLength

Functions

func CopyInterface

func CopyInterface(destValue reflect.Value, src interface{}) error

CopyInterface is a copy of convertAssign from the sql package It copies a value from a src to a destination interface converting types as appropriate. Ideally we would want to have this interface exported.. but the Powers-that-be decided to keep it private so we have to clone it here.

func FieldByPath

func FieldByPath(v reflect.Value, name string) (reflect.Value, error)

FieldByPath returns the struct field with the given path It returns the zero Value if no field was found. Note that if there is no period in the name then this is exactly the same as FieldMyName (except it doesn't panic)

func InsertRecord

func InsertRecord(db *sqlx.DB, tableName string, record interface{}) (sql.Result, error)

InsertRecord allows you to insert a new record into a table respecting nulls

func Marshall

func Marshall(source interface{}, dest interface{}) error

Marshall copies the values to a database structure from an internal representation structure using the annotations on the database structure to indicate which field to copy to. This maps null fields from the database (stored in the sql.NullString... structures) into an appropriate null value.

func MarshallInsertRecord

func MarshallInsertRecord(db *sqlx.DB, table string, data interface{}, dbTemplate interface{}) (resID int64, err error)

MarshallInsertRecord inserts a record of any type into the database and returns the insertId from that record if it succeeds or any errors if it fails For the dbTemplate you must pass in an empty structure by address to allow the data to be marshalled

func MarshallUpdateRecord

func MarshallUpdateRecord(db *sqlx.DB, table string, data interface{}, dbTemplate interface{}) (resID int64, err error)

MarshallUpdateRecord finds the record based on the table name and the autoIncrementing key. NOTE: Whatever structure is inserted into the table, the incrementing key must be the ONLY incrementing key in the table and it must be the same as the record you are hoping to update

func Query

func Query(db *sqlx.DB, query string, dbTemplate interface{}, data interface{}, args ...interface{}) (err error)

Query executes a query on the database for a single record into a database template and then marshalls the result into a data interface. If no records are found for the query, sql.ErrNoRows is returned

func UnMarshall

func UnMarshall(source interface{}, dest interface{}) error

UnMarshall copies the values from a database structure into an internal representation structure using the annotations on the database structure to indicate which field to copy to. This maps null fields from the database (stored in the sql.NullString... structures) into an appropriate null value.

func UpdateRecord

func UpdateRecord(db *sqlx.DB, tableName string, record interface{}) (sql.Result, error)

UpdateRecord allows you to update an existing record in the database

func VerifySQLTableName

func VerifySQLTableName(tableName string) (err error)

VerifySQLTableName checks for potential SQL injection errors by confirming that the table name does not contain anything but alpha numeric and underscore characters

Types

This section is empty.

Jump to

Keyboard shortcuts

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