record

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllField

func AllField(ti TableRecordInterface) string

AllField - Return all select fields

func Delete

func Delete(ti TableRecordInterface) (int64, error)

Delete - Deletes the model from database

func FetchSingleRow

func FetchSingleRow(tri TableRecordInterface, query string, params ...interface{}) error

FetchSingleRow - Execs the query and retrieves only the first result

func GetFieldMapper

func GetFieldMapper(ti TableRecordInterface) (fieldsName []string, fieldsValue []interface{})

GetFieldMapper - Returns a slice of table name fields and a slice of struct field ptr

func GetPrimaryKeyValue

func GetPrimaryKeyValue(ti TableRecordInterface) interface{}

GetPrimaryKeyValue - Returs the primary key value

func LoadByID

func LoadByID(ti TableRecordInterface, id interface{}) error

LoadByID - Loads the model passed by primary key value

func LoadFromRow

func LoadFromRow(r *sqlx.Rows, tri TableRecordInterface) error

LoadFromRow - Loads the passed TableRecordInterface with the row sql result

func Save

func Save(ti TableRecordInterface) error

Save - Saves the model to the database, if the model is "new" inserts a new one otherwise update the record

Types

type NewTableModel

type NewTableModel func() TableRecordInterface

NewTableModel - Defines a func that return a TableRecordInterface

type TableRecord

type TableRecord struct {
	builder.Builder
	// contains filtered or unexported fields
}

TableRecord - Common struct to access all utility func with TableRecordInterface implements QueryBuilderInterface

func NewTableRecord

func NewTableRecord(isNew bool, isReadOnly bool) *TableRecord

NewTableRecord - Returns a new instance of TableRecord

func (*TableRecord) DriverName

func (t *TableRecord) DriverName() string

DriverName - Returns the sql driver name for TableRecord's instance

func (*TableRecord) GetDB

func (t *TableRecord) GetDB() db.SQLConnector

GetDB - Returns TableRecord db resource instance

func (*TableRecord) IsLoaded

func (t *TableRecord) IsLoaded() bool

IsLoaded - Returns if TableRecord is loaded successfully, might useful after a LoadByID or similar func

func (*TableRecord) IsNew

func (t *TableRecord) IsNew() bool

IsNew - Returns if the record is new

func (*TableRecord) PrepareStmt

func (t *TableRecord) PrepareStmt(tableName string) (*sqlx.Stmt, error)

PrepareStmt - Returns the query stmt built with QueryBuilder

func (*TableRecord) SetIsNew

func (t *TableRecord) SetIsNew(new bool) *TableRecord

SetIsNew - Sets isNew field

func (*TableRecord) SetSQLConnection

func (t *TableRecord) SetSQLConnection(db db.SQLConnector) *TableRecord

SetSQLConnection - Sets the db resource instance

type TableRecordInterface

type TableRecordInterface interface {
	GetTableRecord() *TableRecord
	GetPrimaryKeyName() string
	GetTableName() string
}

TableRecordInterface - Defines a generics struct to interact with database

func All

All - Returns all models from database, requires a func constructor that return a TableRecordInterface

func ExecQuery

ExecQuery - Execs the query built with QueryBuilder

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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