dtegorm

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNewDate             = errors.New("failed to create new date")
	ErrDateScan            = errors.New("failed to scan value into date struct")
	ErrDateScanInvalidType = errors.New("invalid type passed to scan")
)
View Source
var (
	ErrNewTime             = errors.New("failed to create new time")
	ErrTimeScan            = errors.New("failed to scan value into time struct")
	ErrTimeScanInvalidType = errors.New("invalid type passed to scan")
)

Functions

This section is empty.

Types

type Date added in v0.1.0

type Date struct {
	dte.Date `example:"2006-01-02" format:"date"`
}
Example
dbName, dsn, db := Setup()
dsn = strings.ReplaceAll(dsn, "dbname="+dbName, "dbname=postgres")
defer Teardown(dbName, dsn, db)
// ^^^ Setup for the PG DB. This can be ignored

type DateExample struct {
	ID       uint `gorm:"primarykey"`
	OnlyDate dtegorm.Date
}

onlyDate, err := dtegorm.NewDate("2006-01-02")
if err != nil {
	return
}

example := DateExample{OnlyDate: onlyDate}

createResult := db.Create(&example)
if createResult.Error != nil {
	return
}

var exampleResult DateExample

getResult := db.First(&exampleResult, example.ID)
if getResult.Error != nil {
	return
}

fmt.Println(exampleResult.OnlyDate.String())
Output:

2006-01-02

func NewDate added in v0.1.0

func NewDate(s string) (Date, error)

func (Date) GormDBDataType added in v0.1.0

func (Date) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType returns gorm DB data type based on the current using database.

func (Date) GormDataType added in v0.1.0

func (Date) GormDataType() string

GormDataType returns gorm common data type. This type is used for the field's column type.

func (*Date) Scan added in v0.1.0

func (d *Date) Scan(src interface{}) error

Scan implements sql.Scanner interface and scans value into Date,.

func (Date) Value added in v0.1.0

func (d Date) Value() (driver.Value, error)

Value implements driver.Valuer interface and returns string format of Date.

type Time

type Time struct {
	dte.Time `example:"15:04:05Z" format:"time"`
}
Example
dbName, dsn, db := Setup()
dsn = strings.ReplaceAll(dsn, "dbname="+dbName, "dbname=postgres")
defer Teardown(dbName, dsn, db)
// ^^^ Setup for the PG DB. This can be ignored

type TimeExample struct {
	ID       uint `gorm:"primarykey"`
	OnlyTime dtegorm.Time
}

onlyTime, err := dtegorm.NewTime("10:04:05-05:00")
if err != nil {
	return
}

example := TimeExample{OnlyTime: onlyTime}

createResult := db.Create(&example)
if createResult.Error != nil {
	return
}

var exampleResult TimeExample

getResult := db.First(&exampleResult, example.ID)
if getResult.Error != nil {
	return
}

fmt.Println(exampleResult.OnlyTime.String())
Output:

15:04:05Z

func NewTime

func NewTime(s string) (Time, error)

func (Time) GormDBDataType

func (Time) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType returns gorm DB data type based on the current using database.

func (Time) GormDataType

func (Time) GormDataType() string

GormDataType returns gorm common data type. This type is used for the field's column type.

func (*Time) Scan

func (t *Time) Scan(src interface{}) error

Scan implements sql.Scanner interface and scans value into Time,.

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value implements driver.Valuer interface and returns string format of Time.

Jump to

Keyboard shortcuts

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