types

package
v0.0.0-...-bd732ee Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package types defines some Go structs to use as models and destinations while testing and benchmarking sqlh.

Index

Constants

This section is empty.

Variables

View Source
var AddressRecords []*Address

AddressRecords is initialized when importing the package.

View Source
var AddressTableName = "sqlh_addresses"

Model table names.

View Source
var SaleRecords []*SaleReport

SaleRecords is initialized when importing the package.

View Source
var SizeAddressRecords int
View Source
var SizeSaleRecords int

Functions

func NewMapper

func NewMapper() *set.Mapper

NewMapper returns an appropriate *set.Mapper for the types in this package.

func NewModels

func NewModels(grammar *grammar.Grammar) *model.Models

NewModels returns a model.Models for the types in this package.

Types

type Address

type Address struct {
	Id           int    `json:"id" db:"pk" model:"key,auto" gorm:"column:pk;primaryKey"`
	CreatedTime  Time   `json:"created_time" db:"created_tmz" model:"inserted" gorm:"-"`
	ModifiedTime Time   `json:"modified_time" db:"modified_tmz" model:"inserted,updated" gorm:"-"`
	Street       string `json:"street"`
	City         string `json:"city"`
	State        string `json:"state"`
	Zip          string `json:"zip"`
	// contains filtered or unexported fields
}

Address model to represent an address.

Methods like Pop, Push, PreInsert, TestInsert, and TestUpdate are present to simplify test code and are not required by the model package.

func (*Address) MockRows

func (me *Address) MockRows(n int) *sqlmock.Rows

func (*Address) PostInsert

func (me *Address) PostInsert(b *testing.B)

func (*Address) PostUpdate

func (me *Address) PostUpdate(b *testing.B)

func (*Address) PreInsert

func (me *Address) PreInsert(b *testing.B)

func (*Address) PreUpdate

func (me *Address) PreUpdate(b *testing.B)

func (*Address) TableName

func (me *Address) TableName() string

TableName overrides the table name used by User to `profiles`.

type MockRows

type MockRows interface {
	MockRows(int) *sqlmock.Rows
}

MockRows is the interface for mocking rows.

type SaleReport

type SaleReport struct {
	Id                 int    `json:"id" db:"pk"`
	CreatedTime        string `json:"created_time" db:"created_tmz"`
	ModifiedTime       string `json:"modified_time" db:"modified_tmz"`
	Price              int    `json:"price" db:"price"`
	Quantity           int    `json:"quantity" db:"quantity"`
	Total              int    `json:"total" db:"total"`
	CustomerId         int    `json:"customer_id" db:"customer_id"`
	CustomerFirst      string `json:"customer_first" db:"customer_first"`
	CustomerLast       string `json:"customer_last" db:"customer_last"`
	VendorId           int    `json:"vendor_id" db:"vendor_id"`
	VendorName         string `json:"vendor_name" db:"vendor_name"`
	VendorDescription  string `json:"vendor_description" db:"vendor_description"`
	VendorContactId    int    `json:"vendor_contact_id" db:"vendor_contact_id"`
	VendorContactFirst string `json:"vendor_contact_first" db:"vendor_contact_first"`
	VendorContactLast  string `json:"vendor_contact_last" db:"vendor_contact_last"`
}

SaleReport is a SELECT destination; it does not represent models.

func (*SaleReport) MockRows

func (me *SaleReport) MockRows(n int) *sqlmock.Rows

type TestModel

type TestModel interface {
	PreInsert(b *testing.B)
	PostInsert(b *testing.B)
	PreUpdate(b *testing.B)
	PostUpdate(b *testing.B)
}

TestModel represents models that we test. By implementing this interface our test code can be more uniform.

type Time

type Time struct {
	time.Time
}

Time overloads time.Time so we can use the same type in our models for CreatedTime and ModifiedTime and use it in multiple database drivers.

var ZeroTime Time

func (*Time) GormDataType

func (*Time) GormDataType() string

func (*Time) Scan

func (me *Time) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*Time) Value

func (me *Time) Value() (driver.Value, error)

Value implements the driver Valuer interface.

Jump to

Keyboard shortcuts

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