db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client() *gorm.DB

func Connect

func Connect() error

func Count

func Count[T any](query any, args ...any) (int64, error)

func Create

func Create[T any](data *T) error

func Delete

func Delete[T any](query any, args ...any) error

func DeleteByID

func DeleteByID[T any](id ...uint64) error

func GetAll

func GetAll[T any](query any, args ...any) ([]T, error)

func GetMany

func GetMany[T any](opt Option) ([]T, error)

func GetOne

func GetOne[T any](query any, args ...any) (T, error)

func GetOneByID

func GetOneByID[T any](id uint64) (T, error)

func Update

func Update[T any](data *T, query any, args ...any) error

Update 仅更新非零值的字段

func UpdateAll added in v0.0.2

func UpdateAll[T any](data *T, query any, args ...any) error

UpdateAll 更新所有字段,即使字段为零值

func UpdateAllByID added in v0.0.2

func UpdateAllByID[T any](id uint64, data *T) error

func UpdateByID

func UpdateByID[T any](id uint64, data *T) error

Types

type Area added in v0.2.0

type Area struct {
	ID     uint64  `gorm:"primaryKey" json:"id"`
	Name   string  `gorm:"index" json:"name"`
	Level  string  `json:"level"` // 等级:country, province, city, district
	AdCode string  `gorm:"index" json:"adcode"`
	Lng    float64 `json:"lng"`
	Lat    float64 `json:"lat"`
	Parent string  `json:"parent"` // 父亲的 adcode
}

Area 行政区域

type BillDetails

type BillDetails struct {
	ID        uint64    `gorm:"primaryKey" json:"id"`
	Money     float64   `gorm:"comment:金额" json:"money"`
	Kind      string    `gorm:"comment:类型" json:"kind"` // income(收入) pay(支出)
	Type      string    `gorm:"comment:分类" json:"type,omitempty"`
	Ledger    string    `gorm:"comment:账本" json:"ledger,omitempty"`
	Note      string    `gorm:"comment:备注" json:"note,omitempty"`
	CreatedAt time.Time `gorm:"index,comment:创建时间" json:"created_at"`
}

BillDetails 明细

type BillLedger added in v0.1.0

type BillLedger struct {
	ID        uint64    `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"comment:名称" json:"name"`
	Note      string    `gorm:"comment:备注" json:"note,omitempty"`
	Times     int       `gorm:"index,comment:使用次数" json:"times,omitempty"`
	CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
	IsDefault bool      `gorm:"comment:默认账本" json:"is_default"`
	Budget    float64   `gorm:"comment:每月预算" json:"budget"`
}

BillType 账本

type BillType added in v0.1.0

type BillType struct {
	ID        uint64    `gorm:"primaryKey" json:"id"`
	Name      string    `gorm:"comment:名称" json:"name"`
	Note      string    `gorm:"comment:备注" json:"note,omitempty"`
	Times     int       `gorm:"index,comment:使用次数" json:"times,omitempty"`
	CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
}

BillType 分类

type File added in v0.2.0

type File struct {
	ID        uint64    `json:"id" gorm:"primaryKey"`
	UsedID    uint64    `json:"used_id" gorm:"index"` // 使用者 ID
	Name      string    `json:"name"`                 // 文件名
	Size      int       `json:"size"`                 // 大小
	CreatedAt time.Time `json:"created_at"`
}

func (*File) Filepath added in v0.2.0

func (f *File) Filepath() string

type FileDao added in v0.2.0

type FileDao struct {
}

func NewFileDao added in v0.2.0

func NewFileDao() *FileDao

func (*FileDao) Create added in v0.2.0

func (f *FileDao) Create(data []byte, ext string) (File, error)

func (*FileDao) Delete added in v0.2.0

func (f *FileDao) Delete(query any, args ...any) error

type Option added in v0.0.2

type Option struct {
	Page  int
	Size  int
	Query any
	Args  []any
	Order string
}

type TomatoPlan added in v0.3.0

type TomatoPlan struct {
	ID             uint64       `json:"id" gorm:"primaryKey"`
	Title          string       `json:"title"`
	Description    string       `json:"description"`
	TomatoDuration int          `json:"tomato_duration"` // 每个番茄的时长,单位为分钟
	CreatedAt      time.Time    `json:"created_at" gorm:"index"`
	Tasks          []TomatoTask `json:"tasks" gorm:"foreignKey:PlanID"`
	Predict        int          `json:"predict"`   // 预估可投入的番茄数
	Cost           int          `json:"cost"`      // 实际投入的番茄数
	CostTime       int          `json:"cost_time"` // 投入时间 = TomatoDuration * Cost
}

type TomatoPlanDao added in v0.3.0

type TomatoPlanDao struct {
}

func NewTomatoPlanDao added in v0.3.0

func NewTomatoPlanDao() *TomatoPlanDao

func (*TomatoPlanDao) Delete added in v0.3.0

func (t *TomatoPlanDao) Delete(query any, args ...any) error

type TomatoTask added in v0.3.0

type TomatoTask struct {
	ID          uint64    `json:"id" gorm:"primaryKey"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	Status      string    `json:"status"` // todo,doing,done
	CreatedAt   time.Time `json:"created_at" gorm:"index"`
	Predict     int       `json:"predict"` // 预估需要的番茄数
	Cost        int       `json:"cost"`    // 实际投入的番茄数
	PlanID      uint64    `json:"plan_id" gorm:"index"`
}

type Travel added in v0.2.0

type Travel struct {
	ID        uint64    `json:"id" gorm:"primaryKey"`
	Name      string    `json:"name"`  // 名称 Area.Name
	Level     string    `json:"level"` // 级别 Area.Level
	Note      string    `json:"note"`  // 备注
	CreatedAt time.Time `json:"created_at" gorm:"index"`
	Files     []File    `json:"files" gorm:"foreignKey:UsedID"` // 文件列表
}

type TravelDao added in v0.2.0

type TravelDao struct {
}

func NewTravelDao added in v0.2.0

func NewTravelDao() *TravelDao

func (TravelDao) Delete added in v0.2.0

func (t TravelDao) Delete(query any, args ...any) error

func (TravelDao) GetMany added in v0.2.0

func (t TravelDao) GetMany(opt Option) ([]Travel, error)

Jump to

Keyboard shortcuts

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