package
0.1.1
Repository: https://github.com/dotnetage/go-titan.git
Documentation: pkg.go.dev

# README

Repository 模式

import (
    "go-titan/repository"
)

func main() {
    repos := repository.New(
        repository.WithPostgre(
            DBName("testdb"),
            DBUser("titan"),
            DBPwd("titan"),
        ))
}

建模

titan 的默认使用gorm实现Repository,模型的声明请参考 GORM的声明模型中的内容

由于是通用模型所以对特殊的字段类型建议使用gorm.io/datatypes提供的数据类型。

type ComposeData struct {
	ID     string `gorm:"primaryKey;"`
	Secret []byte
	Tags  []string `gorm:"type:text[]"`
	Metas datatypes.JSON
}

新增

testUser := &UserTest{
		Name:  gofakeit.UserName(),
		Email: gofakeit.Email(),
	}
err = repos.Add(testUser)
require.NoError(t, err)

删除

查询

更新