datatypes

package
v0.0.0-...-acbd5a7 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

The datatype package implements custom data types like Date and JSON.

Copyright 2022 Dr. Abiira Nathan. All rights reserved. Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date time.Time

Custom date type to support dates of the format "2006-01-02".

Create a new date instance with Date.FromString

func NewDate

func NewDate(year int, month time.Month, day int, loc *time.Location) Date

Create a new date from year,month and day loc is the timezone location

func (Date) Day

func (date Date) Day() int

Returns the day for date

func (Date) FromString

func (Date) FromString(date string) (Date, error)

FromString creates a new Date object from date string.

If date is not of format matching layout: "2006-01-02", it returns an error

func (*Date) GobDecode

func (date *Date) GobDecode(b []byte) error

func (Date) GobEncode

func (date Date) GobEncode() ([]byte, error)

func (Date) GormDataType

func (date Date) GormDataType() string

GormDataType gorm common data type

func (Date) MarshalJSON

func (date Date) MarshalJSON() ([]byte, error)

Custom Json encoder Called when go types are being converted to json strings

func (Date) Month

func (date Date) Month() time.Month

Returns the month for date

func (*Date) Scan

func (date *Date) Scan(value interface{}) (err error)

Satisfy database Scanner interface

func (Date) String

func (date Date) String() string

Stringer interface for date Of the format 2018-01-30

func (*Date) UnmarshalJSON

func (date *Date) UnmarshalJSON(data []byte) error

Custom Json decoder Called to convert json strings to go types

func (Date) Value

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

Satisfy database Valuer interface

func (Date) Year

func (date Date) Year() int

Returns the year for date

type JSON

type JSON map[string]interface{}

Custom JSON data type that implements the sql.Scanner and driver.Valuer interfaces to work with postgres database.

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value returns the json value

Implement driver.Valuer interface

Jump to

Keyboard shortcuts

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