sample

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BarFilter

func BarFilter(filterFunc func(bar *Bar) bool) func(query *BarQuery) *BarQuery

BarFilter is an option to change the filtering behavior of BarQuery.

func BarSort

func BarSort(sortFunc func(bars []*Bar)) func(query *BarQuery) *BarQuery

BarSort is an option to change the sorting behavior of BarQuery.

func DeleteBar

func DeleteBar(userID int, datetime sheetdb.Datetime) error

DeleteBar deletes bar from user. If it can not be found, this function returns *sheetdb.NotFoundError.

func DeleteFoo

func DeleteFoo(userID int, fooID int) error

DeleteFoo deletes foo and it's children fooChild from user. If it can not be found, this function returns *sheetdb.NotFoundError.

func DeleteFooChild

func DeleteFooChild(userID int, fooID int, childID int) error

DeleteFooChild deletes fooChild from foo. If it can not be found, this function returns *sheetdb.NotFoundError.

func DeleteTypeTest

func DeleteTypeTest(id int) error

DeleteTypeTest deletes typeTest. If it can not be found, this function returns *sheetdb.NotFoundError.

func DeleteUser

func DeleteUser(userID int) error

DeleteUser deletes user and it's children foo, fooChild and bar. If it can not be found, this function returns *sheetdb.NotFoundError.

func FooChildFilter

func FooChildFilter(filterFunc func(fooChild *FooChild) bool) func(query *FooChildQuery) *FooChildQuery

FooChildFilter is an option to change the filtering behavior of FooChildQuery.

func FooChildSort

func FooChildSort(sortFunc func(fooChildren []*FooChild)) func(query *FooChildQuery) *FooChildQuery

FooChildSort is an option to change the sorting behavior of FooChildQuery.

func FooFilter

func FooFilter(filterFunc func(foo *Foo) bool) func(query *FooQuery) *FooQuery

FooFilter is an option to change the filtering behavior of FooQuery.

func FooSort

func FooSort(sortFunc func(foos []*Foo)) func(query *FooQuery) *FooQuery

FooSort is an option to change the sorting behavior of FooQuery.

func Initialize

func Initialize(ctx context.Context, spreadsheetID string) error

Initialize initializes this package.

func LoadData

func LoadData(ctx context.Context) error

LoadData loads data from the spreadsheet.

func TypeTestFilter

func TypeTestFilter(filterFunc func(typeTest *TypeTest) bool) func(query *TypeTestQuery) *TypeTestQuery

TypeTestFilter is an option to change the filtering behavior of TypeTestQuery.

func TypeTestSort

func TypeTestSort(sortFunc func(typeTests []*TypeTest)) func(query *TypeTestQuery) *TypeTestQuery

TypeTestSort is an option to change the sorting behavior of TypeTestQuery.

func UserFilter

func UserFilter(filterFunc func(user *User) bool) func(query *UserQuery) *UserQuery

UserFilter is an option to change the filtering behavior of UserQuery.

func UserSort

func UserSort(sortFunc func(users []*User)) func(query *UserQuery) *UserQuery

UserSort is an option to change the sorting behavior of UserQuery.

Types

type Bar

type Bar struct {
	UserID   int              `json:"user_id" db:"primarykey"`
	Datetime sheetdb.Datetime `json:"datetime" db:"primarykey"`
	Value    float32          `json:"value"`
	Note     string           `json:"note" db:"allowempty"`
}

Bar is a struct of bar which is a child of user.

func AddBar

func AddBar(userID int, datetime sheetdb.Datetime, value float32, note string) (*Bar, error)

AddBar adds new bar to user. If primary keys already exist, this function returns *sheetdb.DuplicationError. If any fields are invalid, this function returns error.

func GetAllBars added in v0.2.0

func GetAllBars(opts ...BarQueryOption) ([]*Bar, error)

GetBars returns all bars. If any options are specified, the result according to the specified option is returned. If there are no bar to return, this function returns an nil array. If the sort option is not specified, the order of bars is random.

func GetBar

func GetBar(userID int, datetime sheetdb.Datetime) (*Bar, error)

GetBar returns a bar by primary keys. If it can not be found, this function returns *sheetdb.NotFoundError.

func GetBars

func GetBars(userID int, opts ...BarQueryOption) ([]*Bar, error)

GetBars returns all bars that user has. If any options are specified, the result according to the specified option is returned. If there are no bar to return, this function returns an nil array. If the sort option is not specified, the order of bars is random.

func UpdateBar

func UpdateBar(userID int, datetime sheetdb.Datetime, value float32, note string) (*Bar, error)

UpdateBar updates bar. If it can not be found, this function returns *sheetdb.NotFoundError. If any fields are invalid, this function returns error.

type BarQuery

type BarQuery struct {
	// contains filtered or unexported fields
}

BarQuery is used for selecting bars.

type BarQueryOption

type BarQueryOption func(query *BarQuery) *BarQuery

BarQueryOption is an option to change the behavior of BarQuery.

type Foo

type Foo struct {
	UserID int     `json:"user_id" db:"primarykey"`
	FooID  int     `json:"foo_id" db:"primarykey"`
	Value  float32 `json:"value"`
	Note   string  `json:"note" db:"allowempty"`
}

Foo is a struct of foo which is a child of user.

func AddFoo

func AddFoo(userID int, value float32, note string) (*Foo, error)

AddFoo adds new foo to user. FooID is generated automatically. If any fields are invalid, this function returns error.

func GetAllFoos added in v0.2.0

func GetAllFoos(opts ...FooQueryOption) ([]*Foo, error)

GetFoos returns all foos. If any options are specified, the result according to the specified option is returned. If there are no foo to return, this function returns an nil array. If the sort option is not specified, the order of foos is random.

func GetFoo

func GetFoo(userID int, fooID int) (*Foo, error)

GetFoo returns a foo by primary keys. If it can not be found, this function returns *sheetdb.NotFoundError.

func GetFoos

func GetFoos(userID int, opts ...FooQueryOption) ([]*Foo, error)

GetFoos returns all foos that user has. If any options are specified, the result according to the specified option is returned. If there are no foo to return, this function returns an nil array. If the sort option is not specified, the order of foos is random.

func UpdateFoo

func UpdateFoo(userID int, fooID int, value float32, note string) (*Foo, error)

UpdateFoo updates foo. If it can not be found, this function returns *sheetdb.NotFoundError. If any fields are invalid, this function returns error.

func (*Foo) AddFooChild

func (m *Foo) AddFooChild(value string) (*FooChild, error)

AddFooChild adds new fooChild to foo. ChildID is generated automatically. If any fields are invalid, this method returns error.

func (*Foo) DeleteFooChild

func (m *Foo) DeleteFooChild(childID int) error

DeleteFooChild deletes fooChild from foo. If it can not be found, this method returns *sheetdb.NotFoundError.

func (*Foo) GetFooChild

func (m *Foo) GetFooChild(childID int) (*FooChild, error)

GetFooChild returns a fooChild by ChildID. If it can not be found, this method returns *sheetdb.NotFoundError.

func (*Foo) GetFooChildByValue

func (m *Foo) GetFooChildByValue(value string) (*FooChild, error)

GetFooChildByValue returns a fooChild by Value. If it can not be found, this method returns *sheetdb.NotFoundError.

func (*Foo) GetFooChildren

func (m *Foo) GetFooChildren(opts ...FooChildQueryOption) ([]*FooChild, error)

GetFooChildren returns all fooChildren that foo has. If any options are specified, the result according to the specified option is returned. If there are no fooChild to return, this method returns an nil array. If the sort option is not specified, the order of fooChildren is random.

func (*Foo) UpdateFooChild

func (m *Foo) UpdateFooChild(childID int, value string) (*FooChild, error)

UpdateFooChild updates fooChild. If it can not be found, this method returns *sheetdb.NotFoundError. If any fields are invalid, this method returns error.

type FooChild

type FooChild struct {
	UserID  int    `json:"user_id" db:"primarykey"`
	FooID   int    `json:"foo_id" db:"primarykey"`
	ChildID int    `json:"child_id" db:"primarykey"`
	Value   string `json:"value" db:"unique"`
}

FooChild is a struct of foo child.

func AddFooChild

func AddFooChild(userID int, fooID int, value string) (*FooChild, error)

AddFooChild adds new fooChild to foo. ChildID is generated automatically. If any fields are invalid, this function returns error.

func GetAllFooChildren added in v0.2.0

func GetAllFooChildren(opts ...FooChildQueryOption) ([]*FooChild, error)

GetFooChildren returns all fooChildren. If any options are specified, the result according to the specified option is returned. If there are no fooChild to return, this function returns an nil array. If the sort option is not specified, the order of fooChildren is random.

func GetFooChild

func GetFooChild(userID int, fooID int, childID int) (*FooChild, error)

GetFooChild returns a fooChild by primary keys. If it can not be found, this function returns *sheetdb.NotFoundError.

func GetFooChildByValue

func GetFooChildByValue(userID int, fooID int, value string) (*FooChild, error)

GetFooChildByValue returns a fooChild by Value. If it can not be found, this function returns *sheetdb.NotFoundError.

func GetFooChildren

func GetFooChildren(userID int, fooID int, opts ...FooChildQueryOption) ([]*FooChild, error)

GetFooChildren returns all fooChildren that foo has. If any options are specified, the result according to the specified option is returned. If there are no fooChild to return, this function returns an nil array. If the sort option is not specified, the order of fooChildren is random.

func UpdateFooChild

func UpdateFooChild(userID int, fooID int, childID int, value string) (*FooChild, error)

UpdateFooChild updates fooChild. If it can not be found, this function returns *sheetdb.NotFoundError. If any fields are invalid, this function returns error.

type FooChildQuery

type FooChildQuery struct {
	// contains filtered or unexported fields
}

FooChildQuery is used for selecting fooChildren.

type FooChildQueryOption

type FooChildQueryOption func(query *FooChildQuery) *FooChildQuery

FooChildQueryOption is an option to change the behavior of FooChildQuery.

type FooQuery

type FooQuery struct {
	// contains filtered or unexported fields
}

FooQuery is used for selecting foos.

type FooQueryOption

type FooQueryOption func(query *FooQuery) *FooQuery

FooQueryOption is an option to change the behavior of FooQuery.

type Sex

type Sex int

Sex is user's sex.

const (
	UnknownSex Sex = iota
	Male
	Female
)

Sex Enumuration.

func NewSex

func NewSex(sex string) (Sex, error)

NewSex returns new Sex.

func (Sex) MarshalJSON

func (s Sex) MarshalJSON() ([]byte, error)

MarshalJSON marshals sex value.

func (*Sex) String

func (s *Sex) String() string

String returns sex string.

type TypeTest

type TypeTest struct {
	ID             int               `json:"id" db:"primarykey"`
	StringValue    string            `json:"string_value"`
	BoolValue      bool              `json:"bool_value"`
	IntValue       int               `json:"int_value"`
	Int8Value      int8              `json:"int8_value"`
	Int16Value     int16             `json:"int16_value"`
	Int32Value     int32             `json:"int32_value"`
	Int64Value     int64             `json:"int64_value"`
	UintValue      uint              `json:"uint_value"`
	Uint8Value     uint8             `json:"uint8_value"`
	Uint16Value    uint16            `json:"uint16_value"`
	Uint32Value    uint32            `json:"uint32_value"`
	Uint64Value    uint64            `json:"uint64_value"`
	Float32Value   float32           `json:"float32_value"`
	Float64Value   float64           `json:"float64_value"`
	DateValue      sheetdb.Date      `json:"date_value"`
	DatetimeValue  sheetdb.Datetime  `json:"datetime_value"`
	CustomValue    Sex               `json:"custom_value"`
	PBoolValue     *bool             `json:"p_bool_value"`
	PIntValue      *int              `json:"p_int_value"`
	PInt8Value     *int8             `json:"p_int8_value"`
	PInt16Value    *int16            `json:"p_int16_value"`
	PInt32Value    *int32            `json:"p_int32_value"`
	PInt64Value    *int64            `json:"p_int64_value"`
	PUintValue     *uint             `json:"p_uint_value"`
	PUint8Value    *uint8            `json:"p_uint8_value"`
	PUint16Value   *uint16           `json:"p_uint16_value"`
	PUint32Value   *uint32           `json:"p_uint32_value"`
	PUint64Value   *uint64           `json:"p_uint64_value"`
	PFloat32Value  *float32          `json:"p_float32_value"`
	PFloat64Value  *float64          `json:"p_float64_value"`
	PDateValue     *sheetdb.Date     `json:"p_date_value"`
	PDatetimeValue *sheetdb.Datetime `json:"p_datetime_value"`
	PCustomValue   *Sex              `json:"p_custom_value"`
}

TypeTest is a struct for type test.

func AddTypeTest

func AddTypeTest(stringValue string, boolValue bool, intValue int, int8Value int8, int16Value int16, int32Value int32, int64Value int64, uintValue uint, uint8Value uint8, uint16Value uint16, uint32Value uint32, uint64Value uint64, float32Value float32, float64Value float64, dateValue sheetdb.Date, datetimeValue sheetdb.Datetime, customValue Sex, pBoolValue *bool, pIntValue *int, pInt8Value *int8, pInt16Value *int16, pInt32Value *int32, pInt64Value *int64, pUIntValue *uint, pUInt8Value *uint8, pUInt16Value *uint16, pUInt32Value *uint32, pUInt64Value *uint64, pFloat32Value *float32, pFloat64Value *float64, pDateValue *sheetdb.Date, pDatetimeValue *sheetdb.Datetime, pCustomValue *Sex) (*TypeTest, error)

AddTypeTest adds new typeTest. ID is generated automatically. If any fields are invalid, this function returns error.

func GetAllTypeTests added in v0.2.0

func GetAllTypeTests(opts ...TypeTestQueryOption) ([]*TypeTest, error)

GetTypeTests returns all typeTests. If any options are specified, the result according to the specified option is returned. If there are no typeTest to return, this function returns an nil array. If the sort option is not specified, the order of typeTests is random.

func GetTypeTest

func GetTypeTest(id int) (*TypeTest, error)

GetTypeTest returns a typeTest by ID. If it can not be found, this function returns *sheetdb.NotFoundError.

func UpdateTypeTest

func UpdateTypeTest(id int, stringValue string, boolValue bool, intValue int, int8Value int8, int16Value int16, int32Value int32, int64Value int64, uintValue uint, uint8Value uint8, uint16Value uint16, uint32Value uint32, uint64Value uint64, float32Value float32, float64Value float64, dateValue sheetdb.Date, datetimeValue sheetdb.Datetime, customValue Sex, pBoolValue *bool, pIntValue *int, pInt8Value *int8, pInt16Value *int16, pInt32Value *int32, pInt64Value *int64, pUIntValue *uint, pUInt8Value *uint8, pUInt16Value *uint16, pUInt32Value *uint32, pUInt64Value *uint64, pFloat32Value *float32, pFloat64Value *float64, pDateValue *sheetdb.Date, pDatetimeValue *sheetdb.Datetime, pCustomValue *Sex) (*TypeTest, error)

UpdateTypeTest updates typeTest. If it can not be found, this function returns *sheetdb.NotFoundError. If any fields are invalid, this function returns error.

type TypeTestQuery

type TypeTestQuery struct {
	// contains filtered or unexported fields
}

TypeTestQuery is used for selecting typeTests.

type TypeTestQueryOption

type TypeTestQueryOption func(query *TypeTestQuery) *TypeTestQuery

TypeTestQueryOption is an option to change the behavior of TypeTestQuery.

type User

type User struct {
	UserID   int           `json:"user_id" db:"primarykey"`
	Name     string        `json:"name"`
	Email    string        `json:"email" db:"unique"`
	Sex      Sex           `json:"sex"`
	Birthday *sheetdb.Date `json:"birthday"`
}

User is a struct of user.

func AddUser

func AddUser(name string, email string, sex Sex, birthday *sheetdb.Date) (*User, error)

AddUser adds new user. UserID is generated automatically. If any fields are invalid, this function returns error.

func GetAllUsers added in v0.2.0

func GetAllUsers(opts ...UserQueryOption) ([]*User, error)

GetUsers returns all users. If any options are specified, the result according to the specified option is returned. If there are no user to return, this function returns an nil array. If the sort option is not specified, the order of users is random.

func GetUser

func GetUser(userID int) (*User, error)

GetUser returns a user by UserID. If it can not be found, this function returns *sheetdb.NotFoundError.

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUserByEmail returns a user by Email. If it can not be found, this function returns *sheetdb.NotFoundError.

func UpdateUser

func UpdateUser(userID int, name string, email string, sex Sex, birthday *sheetdb.Date) (*User, error)

UpdateUser updates user. If it can not be found, this function returns *sheetdb.NotFoundError. If any fields are invalid, this function returns error.

func (*User) AddBar

func (m *User) AddBar(datetime sheetdb.Datetime, value float32, note string) (*Bar, error)

AddBar adds new bar to user. If argument 'datetime' already exists in this user, this method returns *sheetdb.DuplicationError. If any fields are invalid, this method returns error.

func (*User) AddFoo

func (m *User) AddFoo(value float32, note string) (*Foo, error)

AddFoo adds new foo to user. FooID is generated automatically. If any fields are invalid, this method returns error.

func (*User) DeleteBar

func (m *User) DeleteBar(datetime sheetdb.Datetime) error

DeleteBar deletes bar from user. If it can not be found, this method returns *sheetdb.NotFoundError.

func (*User) DeleteFoo

func (m *User) DeleteFoo(fooID int) error

DeleteFoo deletes foo and it's children fooChild from user. If it can not be found, this method returns *sheetdb.NotFoundError.

func (*User) GetBar

func (m *User) GetBar(datetime sheetdb.Datetime) (*Bar, error)

GetBar returns a bar by Datetime. If it can not be found, this method returns *sheetdb.NotFoundError.

func (*User) GetBars

func (m *User) GetBars(opts ...BarQueryOption) ([]*Bar, error)

GetBars returns all bars that user has. If any options are specified, the result according to the specified option is returned. If there are no bar to return, this method returns an nil array. If the sort option is not specified, the order of bars is random.

func (*User) GetFoo

func (m *User) GetFoo(fooID int) (*Foo, error)

GetFoo returns a foo by FooID. If it can not be found, this method returns *sheetdb.NotFoundError.

func (*User) GetFoos

func (m *User) GetFoos(opts ...FooQueryOption) ([]*Foo, error)

GetFoos returns all foos that user has. If any options are specified, the result according to the specified option is returned. If there are no foo to return, this method returns an nil array. If the sort option is not specified, the order of foos is random.

func (*User) UpdateBar

func (m *User) UpdateBar(datetime sheetdb.Datetime, value float32, note string) (*Bar, error)

UpdateBar updates bar. If it can not be found, this method returns *sheetdb.NotFoundError. If any fields are invalid, this method returns error.

func (*User) UpdateFoo

func (m *User) UpdateFoo(fooID int, value float32, note string) (*Foo, error)

UpdateFoo updates foo. If it can not be found, this method returns *sheetdb.NotFoundError. If any fields are invalid, this method returns error.

type UserQuery

type UserQuery struct {
	// contains filtered or unexported fields
}

UserQuery is used for selecting users.

type UserQueryOption

type UserQueryOption func(query *UserQuery) *UserQuery

UserQueryOption is an option to change the behavior of UserQuery.

Jump to

Keyboard shortcuts

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