mainModel

package
v0.0.0-...-1e4cd2d Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PreformTestALogTypes = struct {
		Register PreformTestALogType
		Login    PreformTestALogType
	}{
		Register: "Register",
		Login:    "Login",
	}
)
View Source
var UserAndLog = preform.IniPrebuildQueryFactory[*UserAndLogFactory, UserAndLogBody](func(d *UserAndLogFactory) {
	d.User = d.PreformTestASchema.User.SetAlias("User").(*FactoryUser)
	d.UserLog = d.PreformTestASchema.UserLog.SetAlias("UserLog").(*FactoryUserLog)
	d.SetSrc(d.User).
		Join("Inner", d.UserLog, d.PreformTestASchema.UserLog.UserId.Eq(d.PreformTestASchema.User.Id)).DefineCols(
		preform.SetPrebuildQueryCol(d, d.User.Id.SetAlias("UserId"), d.UserId),
		preform.SetPrebuildQueryCol(d, d.User.Name.SetAlias("UserName"), d.UserName),
		preform.SetPrebuildQueryCol(d, d.User.ManagerIds.SetAlias("UserManagerIds"), d.UserManagerIds),
		preform.SetPrebuildQueryCol(d, d.User.CreatedBy.SetAlias("UserCreatedBy"), d.UserCreatedBy),
		preform.SetPrebuildQueryCol(d, d.User.CreatedAt.SetAlias("UserCreatedAt"), d.UserCreatedAt),
		preform.SetPrebuildQueryCol(d, d.User.LoginedAt.SetAlias("UserLoginedAt"), d.UserLoginedAt),
		preform.SetPrebuildQueryCol(d, d.User.Detail.SetAlias("UserDetail"), d.UserDetail),
		preform.SetPrebuildQueryCol(d, d.User.Config.SetAlias("UserConfig"), d.UserConfig),
		preform.SetPrebuildQueryCol(d, d.User.ExtraConfig.SetAlias("UserExtraConfig"), d.UserExtraConfig),
		preform.SetPrebuildQueryCol(d, d.UserLog.Id.SetAlias("UserLogId"), d.UserLogId),
		preform.SetPrebuildQueryCol(d, d.UserLog.UserId.SetAlias("UserLogUserId"), d.UserLogUserId),
		preform.SetPrebuildQueryCol(d, d.UserLog.RelatedLogId.SetAlias("UserLogRelatedLogId"), d.UserLogRelatedLogId),
		preform.SetPrebuildQueryCol(d, d.UserLog.Type.SetAlias("UserLogType"), d.UserLogType),
		preform.SetPrebuildQueryCol(d, d.UserLog.Detail.SetAlias("UserLogDetail"), d.UserLogDetail),
	).
		PreSetWhere(d.PreformTestASchema.UserLog.UserId.NotEq(2))
})

Functions

func CloneAll

func CloneAll(preformTestAName string, preformTestBName string, db ...*sql.DB) (preformTestA *PreformTestASchema, preformTestB *PreformTestBSchema)

func Init

func Init(conn *sql.DB, queryRunnerForTest ...preformShare.QueryRunner)

Types

type BarBody

type BarBody struct {
	preform.Body[BarBody, *FactoryBar]
	Id1 int32 `db:"id1" json:"Id1" dataType:"int4"`
	Id2 int32 `db:"id2" json:"Id2" dataType:"int4"`

	Foo *FooBody
}

func (*BarBody) Delete

func (m *BarBody) Delete(cfg ...preform.EditConfig) (affected int64, err error)

func (BarBody) Factory

func (m BarBody) Factory() *FactoryBar

func (BarBody) FieldValueImmutablePtrs

func (m BarBody) FieldValueImmutablePtrs() []any

func (*BarBody) FieldValuePtr

func (m *BarBody) FieldValuePtr(pos int) any

func (*BarBody) FieldValuePtrs

func (m *BarBody) FieldValuePtrs() []any

func (*BarBody) Insert

func (m *BarBody) Insert(cfg ...preform.EditConfig) error

func (*BarBody) LoadFoo

func (m *BarBody) LoadFoo(noCache ...bool) (*FooBody, error)

func (*BarBody) RelatedByPos

func (m *BarBody) RelatedByPos(pos uint32) any

func (*BarBody) RelatedValuePtrs

func (m *BarBody) RelatedValuePtrs() []any

func (*BarBody) Update

func (m *BarBody) Update(cfg ...preform.UpdateConfig) (affected int64, err error)

type FactoryBar

type FactoryBar struct {
	preform.Factory[*FactoryBar, BarBody]
	Id1 *preform.PrimaryKey[int32] `db:"id1" json:"Id1" dataType:"int4"`
	Id2 *preform.PrimaryKey[int32] `db:"id2" json:"Id2" dataType:"int4"`

	//relations
	Foo *preform.ToOne[*BarBody, *FactoryFoo, FooBody]
}

func (FactoryBar) CloneInstance

func (f FactoryBar) CloneInstance(factory preform.IFactory) preform.IFactory

type FactoryFoo

type FactoryFoo struct {
	preform.Factory[*FactoryFoo, FooBody]
	Id   *preform.PrimaryKey[int32] `db:"id" json:"Id" dataType:"int4" autoKey:"true"`
	Fk1  *preform.Column[int32]     `db:"fk1" json:"Fk1" dataType:"int4"`
	Fk2  *preform.Column[int32]     `db:"fk2" json:"Fk2" dataType:"int4"`
	Bars *preform.ToMany[*FooBody, *FactoryBar, BarBody]
}

func (FactoryFoo) CloneInstance

func (f FactoryFoo) CloneInstance(factory preform.IFactory) preform.IFactory

type FactoryUser

type FactoryUser struct {
	preform.Factory[*FactoryUser, UserBody]
	Id          *preform.PrimaryKey[int32]                                                     `db:"id" json:"Id" dataType:"int4" autoKey:"true"`
	Name        *preform.Column[string]                                                        `db:"name" json:"Name" dataType:"varchar"`
	ManagerIds  *preform.Column[preformTypes.Array[int32]]                                     `db:"manager_ids" json:"ManagerIds" dataType:"_int4"`
	CreatedBy   *preform.ForeignKey[int32]                                                     `db:"created_by" json:"CreatedBy" dataType:"int4"`
	CreatedAt   *preform.Column[time.Time]                                                     `db:"created_at" json:"CreatedAt" dataType:"timestamptz"`
	LoginedAt   *preform.Column[preformTypes.Null[time.Time]]                                  `db:"logined_at" json:"LoginedAt" dataType:"timestamptz"`
	Detail      *preform.Column[preformTypes.Null[preformTypes.JsonRaw[*SrcTypes.UserDetail]]] `db:"detail" json:"Detail" dataType:"jsonb"`
	Config      *preform.Column[preformTypes.JsonRaw[*SrcTypes.UserConfig]]                    `db:"config" json:"Config" dataType:"jsonb" defaultValue:"'{}'::json"`
	ExtraConfig *preform.Column[preformTypes.JsonRaw[SrcTypes.UserConfig]]                     `db:"extra_config" json:"ExtraConfig" dataType:"jsonb" defaultValue:"'{}'::json"`

	//relations
	UserByUserUserFk                *preform.ToOne[*UserBody, *FactoryUser, UserBody]
	UsersByUserUserFk               *preform.ToMany[*UserBody, *FactoryUser, UserBody]
	UserLogs                        *preform.ToMany[*UserBody, *FactoryUserLog, UserLogBody]
	UserLogsByUserLogUserFkRegister *preform.ToMany[*UserBody, *FactoryUserLog, UserLogBody]
}

func (FactoryUser) CloneInstance

func (f FactoryUser) CloneInstance(factory preform.IFactory) preform.IFactory

type FactoryUserLog

type FactoryUserLog struct {
	preform.Factory[*FactoryUserLog, UserLogBody]
	Id           *preform.PrimaryKey[uuid.UUID]                    `db:"id" json:"Id" dataType:"uuid"`
	UserId       *preform.ForeignKey[int32]                        `db:"user_id" json:"UserId" dataType:"int4"`
	RelatedLogId *preform.ForeignKey[preformTypes.Null[uuid.UUID]] `db:"related_log_id" json:"RelatedLogId" dataType:"uuid"`
	Type         *preform.Column[PreformTestALogType]              `db:"type" json:"Type" dataType:"log_type"`
	Detail       *preform.Column[PreformTestALogDetail]            `db:"detail" json:"Detail" dataType:"log_detail"`

	//relations
	UserByUserLogUserFk         *preform.ToOne[*UserLogBody, *FactoryUser, UserBody]
	UserByUserLogUserFkRegister *preform.ToOne[*UserLogBody, *FactoryUser, UserBody]
	UserLogByUserLogUserLogFk   *preform.ToOne[*UserLogBody, *FactoryUserLog, UserLogBody]
	UserLogsByUserLogUserLogFk  *preform.ToMany[*UserLogBody, *FactoryUserLog, UserLogBody]
}

func (FactoryUserLog) CloneInstance

func (f FactoryUserLog) CloneInstance(factory preform.IFactory) preform.IFactory

type FooBody

type FooBody struct {
	preform.Body[FooBody, *FactoryFoo]
	Id   int32 `db:"id" json:"Id" dataType:"int4" autoKey:"true"`
	Fk1  int32 `db:"fk1" json:"Fk1" dataType:"int4"`
	Fk2  int32 `db:"fk2" json:"Fk2" dataType:"int4"`
	Bars []*BarBody
}

func (*FooBody) Delete

func (m *FooBody) Delete(cfg ...preform.EditConfig) (affected int64, err error)

func (FooBody) Factory

func (m FooBody) Factory() *FactoryFoo

func (FooBody) FieldValueImmutablePtrs

func (m FooBody) FieldValueImmutablePtrs() []any

func (*FooBody) FieldValuePtr

func (m *FooBody) FieldValuePtr(pos int) any

func (*FooBody) FieldValuePtrs

func (m *FooBody) FieldValuePtrs() []any

func (*FooBody) Insert

func (m *FooBody) Insert(cfg ...preform.EditConfig) error

func (*FooBody) LoadBars

func (m *FooBody) LoadBars(noCache ...bool) ([]*BarBody, error)

func (*FooBody) RelatedByPos

func (m *FooBody) RelatedByPos(pos uint32) any

func (*FooBody) RelatedValuePtrs

func (m *FooBody) RelatedValuePtrs() []any

func (*FooBody) Update

func (m *FooBody) Update(cfg ...preform.UpdateConfig) (affected int64, err error)

type PreformTestALogDetail

type PreformTestALogDetail struct {
	UserAgent string
	SessionId uuid.UUID
	LastLogin time.Time
}

func (*PreformTestALogDetail) Scan

func (ct *PreformTestALogDetail) Scan(src any) error

func (PreformTestALogDetail) Value

func (ct PreformTestALogDetail) Value() (driver.Value, error)

type PreformTestALogType

type PreformTestALogType string

type PreformTestASchema

type PreformTestASchema struct {
	preform.Schema[*PreformTestASchema, PreformTestASchema]
	User    *FactoryUser
	UserLog *FactoryUserLog
	Foo     *FactoryFoo
}
var (
	PreformTestA *PreformTestASchema
)

func (*PreformTestASchema) Clone

func (s *PreformTestASchema) Clone(name string, db ...*sql.DB) preform.ISchema

func (*PreformTestASchema) Factories

func (s *PreformTestASchema) Factories() []preform.IFactory

type PreformTestBSchema

type PreformTestBSchema struct {
	preform.Schema[*PreformTestBSchema, PreformTestBSchema]
	Bar *FactoryBar
}
var (
	PreformTestB *PreformTestBSchema
)

func (*PreformTestBSchema) Clone

func (s *PreformTestBSchema) Clone(name string, db ...*sql.DB) preform.ISchema

func (*PreformTestBSchema) Factories

func (s *PreformTestBSchema) Factories() []preform.IFactory

type UserAndLogBody

type UserAndLogBody struct {
	preform.QueryBody[UserAndLogBody, *UserAndLogFactory]
	UserId              int32                                                `db:"UserId" json:"Id" dataType:"int4" autoKey:"true"`
	UserName            string                                               `db:"UserName" json:"Name" dataType:"varchar"`
	UserManagerIds      preformTypes.Array[int32]                            `db:"UserManagerIds" json:"ManagerIds" dataType:"_int4"`
	UserCreatedBy       int32                                                `db:"UserCreatedBy" json:"CreatedBy" dataType:"int4"`
	UserCreatedAt       time.Time                                            `db:"UserCreatedAt" json:"CreatedAt" dataType:"timestamptz"`
	UserLoginedAt       preformTypes.Null[time.Time]                         `db:"UserLoginedAt" json:"LoginedAt" dataType:"timestamptz"`
	UserDetail          preformTypes.Null[preformTypes.JsonRaw[interface{}]] `db:"UserDetail" json:"Detail" dataType:"jsonb"`
	UserConfig          preformTypes.JsonRaw[interface{}]                    `db:"UserConfig" json:"Config" dataType:"jsonb" defaultValue:"'{}'::json"`
	UserExtraConfig     preformTypes.JsonRaw[interface{}]                    `db:"UserExtraConfig" json:"ExtraConfig" dataType:"jsonb" defaultValue:"'{}'::json"`
	UserLogId           uuid.UUID                                            `db:"UserLogId" json:"Id" dataType:"uuid"`
	UserLogUserId       int32                                                `db:"UserLogUserId" json:"UserId" dataType:"int4"`
	UserLogRelatedLogId preformTypes.Null[uuid.UUID]                         `db:"UserLogRelatedLogId" json:"RelatedLogId" dataType:"uuid"`
	UserLogType         PreformTestALogType                                  `db:"UserLogType" json:"Type" dataType:"log_type"`
	UserLogDetail       PreformTestALogDetail                                `db:"UserLogDetail" json:"Detail" dataType:"log_detail"`
}

func (UserAndLogBody) Factory

func (m UserAndLogBody) Factory() *UserAndLogFactory

func (*UserAndLogBody) FieldValuePtr

func (m *UserAndLogBody) FieldValuePtr(pos int) any

func (*UserAndLogBody) FieldValuePtrs

func (m *UserAndLogBody) FieldValuePtrs() []any

type UserAndLogFactory

type UserAndLogFactory struct {
	preform.PrebuildQueryFactory[*UserAndLogFactory, UserAndLogBody]
	//schema src
	PreformTestASchema *PreformTestASchema

	//factory src
	User    *FactoryUser
	UserLog *FactoryUserLog

	//columns
	UserId              *preform.PrebuildQueryCol[int32, preform.NoAggregation]
	UserName            *preform.PrebuildQueryCol[string, preform.NoAggregation]
	UserManagerIds      *preform.PrebuildQueryCol[preformTypes.Array[int32], preform.NoAggregation]
	UserCreatedBy       *preform.PrebuildQueryCol[int32, preform.NoAggregation]
	UserCreatedAt       *preform.PrebuildQueryCol[time.Time, preform.NoAggregation]
	UserLoginedAt       *preform.PrebuildQueryCol[preformTypes.Null[time.Time], preform.NoAggregation]
	UserDetail          *preform.PrebuildQueryCol[preformTypes.Null[preformTypes.JsonRaw[interface{}]], preform.NoAggregation]
	UserConfig          *preform.PrebuildQueryCol[preformTypes.JsonRaw[interface{}], preform.NoAggregation]
	UserExtraConfig     *preform.PrebuildQueryCol[preformTypes.JsonRaw[interface{}], preform.NoAggregation]
	UserLogId           *preform.PrebuildQueryCol[uuid.UUID, preform.NoAggregation]
	UserLogUserId       *preform.PrebuildQueryCol[int32, preform.NoAggregation]
	UserLogRelatedLogId *preform.PrebuildQueryCol[preformTypes.Null[uuid.UUID], preform.NoAggregation]
	UserLogType         *preform.PrebuildQueryCol[PreformTestALogType, preform.NoAggregation]
	UserLogDetail       *preform.PrebuildQueryCol[PreformTestALogDetail, preform.NoAggregation]
}

type UserBody

type UserBody struct {
	preform.Body[UserBody, *FactoryUser]
	Id          int32                                                         `db:"id" json:"Id" dataType:"int4" autoKey:"true"`
	Name        string                                                        `db:"name" json:"Name" dataType:"varchar"`
	ManagerIds  preformTypes.Array[int32]                                     `db:"manager_ids" json:"ManagerIds" dataType:"_int4"`
	CreatedBy   int32                                                         `db:"created_by" json:"CreatedBy" dataType:"int4"`
	CreatedAt   time.Time                                                     `db:"created_at" json:"CreatedAt" dataType:"timestamptz"`
	LoginedAt   preformTypes.Null[time.Time]                                  `db:"logined_at" json:"LoginedAt" dataType:"timestamptz"`
	Detail      preformTypes.Null[preformTypes.JsonRaw[*SrcTypes.UserDetail]] `db:"detail" json:"Detail" dataType:"jsonb"`
	Config      preformTypes.JsonRaw[*SrcTypes.UserConfig]                    `db:"config" json:"Config" dataType:"jsonb" defaultValue:"'{}'::json"`
	ExtraConfig preformTypes.JsonRaw[SrcTypes.UserConfig]                     `db:"extra_config" json:"ExtraConfig" dataType:"jsonb" defaultValue:"'{}'::json"`

	UserByUserUserFk                *UserBody
	UsersByUserUserFk               []*UserBody
	UserLogs                        []*UserLogBody
	UserLogsByUserLogUserFkRegister []*UserLogBody
}

func (*UserBody) Delete

func (m *UserBody) Delete(cfg ...preform.EditConfig) (affected int64, err error)

func (UserBody) Factory

func (m UserBody) Factory() *FactoryUser

func (UserBody) FieldValueImmutablePtrs

func (m UserBody) FieldValueImmutablePtrs() []any

func (*UserBody) FieldValuePtr

func (m *UserBody) FieldValuePtr(pos int) any

func (*UserBody) FieldValuePtrs

func (m *UserBody) FieldValuePtrs() []any

func (*UserBody) Insert

func (m *UserBody) Insert(cfg ...preform.EditConfig) error

func (*UserBody) LoadUserByUserUserFk

func (m *UserBody) LoadUserByUserUserFk(noCache ...bool) (*UserBody, error)

func (*UserBody) LoadUserLogs

func (m *UserBody) LoadUserLogs(noCache ...bool) ([]*UserLogBody, error)

func (*UserBody) LoadUserLogsByUserLogUserFkRegister

func (m *UserBody) LoadUserLogsByUserLogUserFkRegister(noCache ...bool) ([]*UserLogBody, error)

func (*UserBody) LoadUsersByUserUserFk

func (m *UserBody) LoadUsersByUserUserFk(noCache ...bool) ([]*UserBody, error)

func (*UserBody) RelatedByPos

func (m *UserBody) RelatedByPos(pos uint32) any

func (*UserBody) RelatedValuePtrs

func (m *UserBody) RelatedValuePtrs() []any

func (*UserBody) Update

func (m *UserBody) Update(cfg ...preform.UpdateConfig) (affected int64, err error)

type UserLogBody

type UserLogBody struct {
	preform.Body[UserLogBody, *FactoryUserLog]
	Id           uuid.UUID                    `db:"id" json:"Id" dataType:"uuid"`
	UserId       int32                        `db:"user_id" json:"UserId" dataType:"int4"`
	RelatedLogId preformTypes.Null[uuid.UUID] `db:"related_log_id" json:"RelatedLogId" dataType:"uuid"`
	Type         PreformTestALogType          `db:"type" json:"Type" dataType:"log_type"`
	Detail       PreformTestALogDetail        `db:"detail" json:"Detail" dataType:"log_detail"`

	UserByUserLogUserFk         *UserBody
	UserByUserLogUserFkRegister *UserBody
	UserLogByUserLogUserLogFk   *UserLogBody
	UserLogsByUserLogUserLogFk  []*UserLogBody
}

func (*UserLogBody) Delete

func (m *UserLogBody) Delete(cfg ...preform.EditConfig) (affected int64, err error)

func (UserLogBody) Factory

func (m UserLogBody) Factory() *FactoryUserLog

func (UserLogBody) FieldValueImmutablePtrs

func (m UserLogBody) FieldValueImmutablePtrs() []any

func (*UserLogBody) FieldValuePtr

func (m *UserLogBody) FieldValuePtr(pos int) any

func (*UserLogBody) FieldValuePtrs

func (m *UserLogBody) FieldValuePtrs() []any

func (*UserLogBody) Insert

func (m *UserLogBody) Insert(cfg ...preform.EditConfig) error

func (*UserLogBody) LoadUserByUserLogUserFk

func (m *UserLogBody) LoadUserByUserLogUserFk(noCache ...bool) (*UserBody, error)

func (*UserLogBody) LoadUserByUserLogUserFkRegister

func (m *UserLogBody) LoadUserByUserLogUserFkRegister(noCache ...bool) (*UserBody, error)

func (*UserLogBody) LoadUserLogByUserLogUserLogFk

func (m *UserLogBody) LoadUserLogByUserLogUserLogFk(noCache ...bool) (*UserLogBody, error)

func (*UserLogBody) LoadUserLogsByUserLogUserLogFk

func (m *UserLogBody) LoadUserLogsByUserLogUserLogFk(noCache ...bool) ([]*UserLogBody, error)

func (*UserLogBody) RelatedByPos

func (m *UserLogBody) RelatedByPos(pos uint32) any

func (*UserLogBody) RelatedValuePtrs

func (m *UserLogBody) RelatedValuePtrs() []any

func (*UserLogBody) Update

func (m *UserLogBody) Update(cfg ...preform.UpdateConfig) (affected int64, err error)

Directories

Path Synopsis
src

Jump to

Keyboard shortcuts

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