example

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const TimestampFormat = "2006-01-02T15:04:05.999999Z07:00"

cockroachdb doesn't support nanosecond timestamp columns so use microsecond instead

Variables

View Source
var (
	EnumOne_name = map[int32]string{
		0: "Default",
		1: "One",
		2: "Two",
		3: "Three",
		4: "Four",
		5: "Five",
		6: "Six",
		7: "Seven",
		8: "Eight",
		9: "Nine",
	}
	EnumOne_value = map[string]int32{
		"Default": 0,
		"One":     1,
		"Two":     2,
		"Three":   3,
		"Four":    4,
		"Five":    5,
		"Six":     6,
		"Seven":   7,
		"Eight":   8,
		"Nine":    9,
	}
)

Enum value maps for EnumOne.

View Source
var File_cockroachdb_example_proto protoreflect.FileDescriptor

Functions

func AssociateManyToMany added in v1.0.1

func AssociateManyToMany[L Models, R Models](ctx context.Context, db *gorm.DB, associations *ManyToManyAssociations, associationName string) error

func Delete added in v1.0.1

func Delete[M Models](ctx context.Context, db *gorm.DB, ids []string) ([]M, error)

Delete is a generic function that will delete any of the generated protos. A function may be provided to be executed during the transaction. The function is executed after the delete. If the function returns an error, the transaction will be rolled back.

func DeleteAddressGormModels

func DeleteAddressGormModels(ctx context.Context, tx *gorm.DB, ids []string) error

func DeleteCommentGormModels

func DeleteCommentGormModels(ctx context.Context, tx *gorm.DB, ids []string) error

func DeleteCompanyGormModels

func DeleteCompanyGormModels(ctx context.Context, tx *gorm.DB, ids []string) error

func DeleteProfileGormModels

func DeleteProfileGormModels(ctx context.Context, tx *gorm.DB, ids []string) error

func DeleteUserGormModels

func DeleteUserGormModels(ctx context.Context, tx *gorm.DB, ids []string) error

func DissociateManyToMany added in v1.0.1

func DissociateManyToMany[L Models, R Models](ctx context.Context, db *gorm.DB, associations *ManyToManyAssociations, associationName string) error

func GetByIds added in v1.0.1

func GetByIds[M Models](ctx context.Context, db *gorm.DB, ids []string, preloads map[string][]interface{}) ([]M, error)

GetByIds gets the given model type by id

func List added in v1.0.1

func List[M Models](ctx context.Context, db *gorm.DB, limit, offset int, orderBy string, preloads map[string][]interface{}) ([]M, error)

List lists the given model type

func ReplaceManyToMany added in v1.0.3

func ReplaceManyToMany[L Models, R Models](ctx context.Context, db *gorm.DB, associations *ManyToManyAssociations, associationName string) error

func ToModels added in v1.0.1

func ToModels[P Protos, M Models](protos interface{}) ([]M, error)

ToModels converts an array of protos to an array of gorm db models by calling the proto's ToModel method

func ToProtos added in v1.0.1

func ToProtos[P Protos, M Models](models interface{}) ([]P, error)

ToProtos converts an array of models into an array of protos by calling the model's ToProto method

func Upsert added in v1.0.1

func Upsert[P Protos, M Models](ctx context.Context, db *gorm.DB, protos interface{}) ([]M, error)

Upsert is a generic function that will upsert any of the generated protos, returning the upserted models. Upsert excludes all associations, and uses an on conflict clause to handle upsert. A function may be provided to be executed during the transaction. The function is executed after the upsert. If the function returns an error, the transaction will be rolled back.

Types

type Address

type Address struct {

	// @gotags: fake:"skip"
	Id *string `protobuf:"bytes,1,opt,name=id,proto3,oneof" json:"id,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	CreatedAt *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty" fake:"skip"`
	// @gotags: fake:"{name}"
	Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty" fake:"{name}"`
	// @gotags: fake:"skip"
	UserId *string `protobuf:"bytes,5,opt,name=user_id,json=userId,proto3,oneof" json:"user_id,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	User *User `protobuf:"bytes,6,opt,name=user,proto3" json:"user,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	CompanyBlob *Company `protobuf:"bytes,7,opt,name=companyBlob,proto3" json:"companyBlob,omitempty" fake:"skip"`
	// contains filtered or unexported fields
}

func (*Address) Descriptor deprecated

func (*Address) Descriptor() ([]byte, []int)

Deprecated: Use Address.ProtoReflect.Descriptor instead.

func (*Address) GetCompanyBlob added in v0.1.32

func (x *Address) GetCompanyBlob() *Company

func (*Address) GetCreatedAt

func (x *Address) GetCreatedAt() *timestamppb.Timestamp

func (*Address) GetId

func (x *Address) GetId() string

func (*Address) GetName

func (x *Address) GetName() string

func (*Address) GetProtoId added in v1.0.1

func (p *Address) GetProtoId() *string

func (*Address) GetUpdatedAt

func (x *Address) GetUpdatedAt() *timestamppb.Timestamp

func (*Address) GetUser added in v0.1.16

func (x *Address) GetUser() *User

func (*Address) GetUserId

func (x *Address) GetUserId() string

func (*Address) MarshalJSON

func (msg *Address) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Address) ProtoMessage

func (*Address) ProtoMessage()

func (*Address) ProtoReflect

func (x *Address) ProtoReflect() protoreflect.Message

func (*Address) Reset

func (x *Address) Reset()

func (*Address) SetProtoId added in v1.0.1

func (p *Address) SetProtoId(id string)

func (*Address) String

func (x *Address) String() string

func (*Address) ToModel

func (p *Address) ToModel() (theModel *AddressGormModel, err error)

func (*Address) UnmarshalJSON

func (msg *Address) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

type AddressGormModel

type AddressGormModel struct {

	// @gotags: fake:"skip"
	Id *string `gorm:"type:uuid;primaryKey;default:gen_random_uuid();;" json:"id" fake:"skip"`

	// @gotags: fake:"skip"
	CreatedAt *time.Time `gorm:"type:timestamp;" json:"createdAt" fake:"skip"`

	// @gotags: fake:"skip"
	UpdatedAt *time.Time `gorm:"type:timestamp;" json:"updatedAt" fake:"skip"`

	// @gotags: fake:"{name}"
	Name string `json:"name" fake:"{name}"`

	// @gotags: fake:"skip"
	UserId *string `json:"userId" fake:"skip"`

	// @gotags: fake:"skip"
	User *UserGormModel `gorm:"foreignKey:UserId;references:Id;constraint:OnDelete:CASCADE;" json:"user" fake:"skip"`

	// @gotags: fake:"skip"
	CompanyBlob gorm_jsonb.JSONB `gorm:"type:jsonb" json:"companyBlob" fake:"skip"`
}

func (*AddressGormModel) GetModelId added in v1.0.1

func (m *AddressGormModel) GetModelId() *string

func (*AddressGormModel) New added in v1.0.1

func (m *AddressGormModel) New() interface{}

func (*AddressGormModel) SetModelId added in v1.0.1

func (m *AddressGormModel) SetModelId(id string)

func (*AddressGormModel) TableName

func (m *AddressGormModel) TableName() string

func (*AddressGormModel) ToProto

func (m *AddressGormModel) ToProto() (theProto *Address, err error)

type AddressGormModels

type AddressGormModels []*AddressGormModel

func (AddressGormModels) GetByModelIds

func (m AddressGormModels) GetByModelIds(ctx context.Context, tx *gorm.DB, preloads ...string) (err error)

func (AddressGormModels) ToProtos

func (m AddressGormModels) ToProtos() (protos AddressProtos, err error)

type AddressProtos

type AddressProtos []*Address

func (*AddressProtos) GetByIds

func (p *AddressProtos) GetByIds(ctx context.Context, tx *gorm.DB, ids []string, preloads ...string) (err error)

func (*AddressProtos) List

func (p *AddressProtos) List(ctx context.Context, tx *gorm.DB, limit, offset int, order interface{}, preloads ...string) (err error)

func (AddressProtos) ToModels

func (p AddressProtos) ToModels() (models AddressGormModels, err error)

func (*AddressProtos) Upsert

func (p *AddressProtos) Upsert(ctx context.Context, tx *gorm.DB) (models AddressGormModels, err error)

Upsert creates the protos using an on conflict clause to do updates. This function does not update *any* associations use gorm's association mode functions to update associations as you see fit after calling upsert. See https://gorm.io/docs/associations.html#Replace-Associations

type Comment

type Comment struct {

	// @gotags: fake:"skip"
	Id *string `protobuf:"bytes,1,opt,name=id,proto3,oneof" json:"id,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	CreatedAt *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty" fake:"skip"`
	// @gotags: fake:"{name}"
	Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty" fake:"{name}"`
	// @gotags: fake:"skip"
	UserId *string `protobuf:"bytes,5,opt,name=userId,proto3,oneof" json:"userId,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	User *User `protobuf:"bytes,6,opt,name=user,proto3" json:"user,omitempty" fake:"skip"`
	// contains filtered or unexported fields
}

func (*Comment) Descriptor deprecated

func (*Comment) Descriptor() ([]byte, []int)

Deprecated: Use Comment.ProtoReflect.Descriptor instead.

func (*Comment) GetCreatedAt

func (x *Comment) GetCreatedAt() *timestamppb.Timestamp

func (*Comment) GetId

func (x *Comment) GetId() string

func (*Comment) GetName

func (x *Comment) GetName() string

func (*Comment) GetProtoId added in v1.0.1

func (p *Comment) GetProtoId() *string

func (*Comment) GetUpdatedAt

func (x *Comment) GetUpdatedAt() *timestamppb.Timestamp

func (*Comment) GetUser added in v1.0.0

func (x *Comment) GetUser() *User

func (*Comment) GetUserId

func (x *Comment) GetUserId() string

func (*Comment) MarshalJSON

func (msg *Comment) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Comment) ProtoMessage

func (*Comment) ProtoMessage()

func (*Comment) ProtoReflect

func (x *Comment) ProtoReflect() protoreflect.Message

func (*Comment) Reset

func (x *Comment) Reset()

func (*Comment) SetProtoId added in v1.0.1

func (p *Comment) SetProtoId(id string)

func (*Comment) String

func (x *Comment) String() string

func (*Comment) ToModel

func (p *Comment) ToModel() (theModel *CommentGormModel, err error)

func (*Comment) UnmarshalJSON

func (msg *Comment) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

type CommentGormModel

type CommentGormModel struct {

	// @gotags: fake:"skip"
	Id *string `gorm:"type:uuid;primaryKey;default:gen_random_uuid();;" json:"id" fake:"skip"`

	// @gotags: fake:"skip"
	CreatedAt *time.Time `gorm:"type:timestamp;" json:"createdAt" fake:"skip"`

	// @gotags: fake:"skip"
	UpdatedAt *time.Time `gorm:"type:timestamp;" json:"updatedAt" fake:"skip"`

	// @gotags: fake:"{name}"
	Name string `json:"name" fake:"{name}"`

	// @gotags: fake:"skip"
	UserId *string `json:"userId" fake:"skip"`

	// @gotags: fake:"skip"
	User *UserGormModel `gorm:"foreignKey:UserId;references:Id;constraint:OnDelete:CASCADE;" json:"user" fake:"skip"`
}

func (*CommentGormModel) GetModelId added in v1.0.1

func (m *CommentGormModel) GetModelId() *string

func (*CommentGormModel) New added in v1.0.1

func (m *CommentGormModel) New() interface{}

func (*CommentGormModel) SetModelId added in v1.0.1

func (m *CommentGormModel) SetModelId(id string)

func (*CommentGormModel) TableName

func (m *CommentGormModel) TableName() string

func (*CommentGormModel) ToProto

func (m *CommentGormModel) ToProto() (theProto *Comment, err error)

type CommentGormModels

type CommentGormModels []*CommentGormModel

func (CommentGormModels) GetByModelIds

func (m CommentGormModels) GetByModelIds(ctx context.Context, tx *gorm.DB, preloads ...string) (err error)

func (CommentGormModels) ToProtos

func (m CommentGormModels) ToProtos() (protos CommentProtos, err error)

type CommentProtos

type CommentProtos []*Comment

func (*CommentProtos) GetByIds

func (p *CommentProtos) GetByIds(ctx context.Context, tx *gorm.DB, ids []string, preloads ...string) (err error)

func (*CommentProtos) List

func (p *CommentProtos) List(ctx context.Context, tx *gorm.DB, limit, offset int, order interface{}, preloads ...string) (err error)

func (CommentProtos) ToModels

func (p CommentProtos) ToModels() (models CommentGormModels, err error)

func (*CommentProtos) Upsert

func (p *CommentProtos) Upsert(ctx context.Context, tx *gorm.DB) (models CommentGormModels, err error)

Upsert creates the protos using an on conflict clause to do updates. This function does not update *any* associations use gorm's association mode functions to update associations as you see fit after calling upsert. See https://gorm.io/docs/associations.html#Replace-Associations

type Company

type Company struct {

	// @gotags: fake:"skip"
	Id *string `protobuf:"bytes,1,opt,name=id,proto3,oneof" json:"id,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	CreatedAt *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty" fake:"skip"`
	// @gotags: fake:"{name}"
	Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty" fake:"{name}"`
	// contains filtered or unexported fields
}

func (*Company) Descriptor deprecated

func (*Company) Descriptor() ([]byte, []int)

Deprecated: Use Company.ProtoReflect.Descriptor instead.

func (*Company) GetCreatedAt

func (x *Company) GetCreatedAt() *timestamppb.Timestamp

func (*Company) GetId

func (x *Company) GetId() string

func (*Company) GetName

func (x *Company) GetName() string

func (*Company) GetProtoId added in v1.0.1

func (p *Company) GetProtoId() *string

func (*Company) GetUpdatedAt

func (x *Company) GetUpdatedAt() *timestamppb.Timestamp

func (*Company) MarshalJSON

func (msg *Company) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Company) ProtoMessage

func (*Company) ProtoMessage()

func (*Company) ProtoReflect

func (x *Company) ProtoReflect() protoreflect.Message

func (*Company) Reset

func (x *Company) Reset()

func (*Company) SetProtoId added in v1.0.1

func (p *Company) SetProtoId(id string)

func (*Company) String

func (x *Company) String() string

func (*Company) ToModel

func (p *Company) ToModel() (theModel *CompanyGormModel, err error)

func (*Company) UnmarshalJSON

func (msg *Company) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

type CompanyGormModel

type CompanyGormModel struct {

	// @gotags: fake:"skip"
	Id *string `gorm:"type:uuid;primaryKey;default:gen_random_uuid();;" json:"id" fake:"skip"`

	// @gotags: fake:"skip"
	CreatedAt *time.Time `gorm:"type:timestamp;" json:"createdAt" fake:"skip"`

	// @gotags: fake:"skip"
	UpdatedAt *time.Time `gorm:"type:timestamp;" json:"updatedAt" fake:"skip"`

	// @gotags: fake:"{name}"
	Name string `json:"name" fake:"{name}"`
}

func (*CompanyGormModel) GetModelId added in v1.0.1

func (m *CompanyGormModel) GetModelId() *string

func (*CompanyGormModel) New added in v1.0.1

func (m *CompanyGormModel) New() interface{}

func (*CompanyGormModel) SetModelId added in v1.0.1

func (m *CompanyGormModel) SetModelId(id string)

func (*CompanyGormModel) TableName

func (m *CompanyGormModel) TableName() string

func (*CompanyGormModel) ToProto

func (m *CompanyGormModel) ToProto() (theProto *Company, err error)

type CompanyGormModels

type CompanyGormModels []*CompanyGormModel

func (CompanyGormModels) GetByModelIds

func (m CompanyGormModels) GetByModelIds(ctx context.Context, tx *gorm.DB, preloads ...string) (err error)

func (CompanyGormModels) ToProtos

func (m CompanyGormModels) ToProtos() (protos CompanyProtos, err error)

type CompanyProtos

type CompanyProtos []*Company

func (*CompanyProtos) GetByIds

func (p *CompanyProtos) GetByIds(ctx context.Context, tx *gorm.DB, ids []string, preloads ...string) (err error)

func (*CompanyProtos) List

func (p *CompanyProtos) List(ctx context.Context, tx *gorm.DB, limit, offset int, order interface{}, preloads ...string) (err error)

func (CompanyProtos) ToModels

func (p CompanyProtos) ToModels() (models CompanyGormModels, err error)

func (*CompanyProtos) Upsert

func (p *CompanyProtos) Upsert(ctx context.Context, tx *gorm.DB) (models CompanyGormModels, err error)

Upsert creates the protos using an on conflict clause to do updates. This function does not update *any* associations use gorm's association mode functions to update associations as you see fit after calling upsert. See https://gorm.io/docs/associations.html#Replace-Associations

type EnumOne

type EnumOne int32
const (
	EnumOne_Default EnumOne = 0
	EnumOne_One     EnumOne = 1
	EnumOne_Two     EnumOne = 2
	EnumOne_Three   EnumOne = 3
	EnumOne_Four    EnumOne = 4
	EnumOne_Five    EnumOne = 5
	EnumOne_Six     EnumOne = 6
	EnumOne_Seven   EnumOne = 7
	EnumOne_Eight   EnumOne = 8
	EnumOne_Nine    EnumOne = 9
)

func (EnumOne) Descriptor

func (EnumOne) Descriptor() protoreflect.EnumDescriptor

func (EnumOne) Enum

func (x EnumOne) Enum() *EnumOne

func (EnumOne) EnumDescriptor deprecated

func (EnumOne) EnumDescriptor() ([]byte, []int)

Deprecated: Use EnumOne.Descriptor instead.

func (EnumOne) Number

func (x EnumOne) Number() protoreflect.EnumNumber

func (EnumOne) String

func (x EnumOne) String() string

func (EnumOne) Type

func (EnumOne) Type() protoreflect.EnumType

type ManyToManyAssociations added in v1.0.1

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

ManyToManyAssociations is a sync map with helper functions. I'm using a sync.map so that it's thread safe, and a struct to allow us to easily define behavior we can use elsewhere

func (*ManyToManyAssociations) AddAssociation added in v1.0.1

func (m *ManyToManyAssociations) AddAssociation(modelId, associatedId string)

func (*ManyToManyAssociations) Associations added in v1.0.1

func (m *ManyToManyAssociations) Associations() map[string][]string

type Model added in v1.0.1

type Model[P Protos] interface {
	ToProto() (P, error)
}

Model[P Protos] is an interface type that defines behavior for the implementer of a given Protos type

func ConvertModelToModelP added in v1.0.1

func ConvertModelToModelP[P Protos, M Models](model interface{}) Model[P]

ConvertProtoToProtosM converts a single proto to a Proto[M]

func ConvertModelsToModelsP added in v1.0.1

func ConvertModelsToModelsP[P Protos, M Models](models interface{}) []Model[P]

ConvertProtosToProtosM converts a given slice of protos into an array of the Proto interface type, which can then leverage the interface methods

type Models added in v1.0.1

type Models interface {
	*UserGormModel | *CompanyGormModel | *AddressGormModel | *CommentGormModel | *ProfileGormModel
	GetModelId() *string
	SetModelId(string)
	New() interface{}
	TableName() string // tabler interface for gorm model, gives us access to the table name that gorm will use, see https://gorm.io/docs/conventions.html#TableName
}

Models is a union of other types that defines which types may be used in generic functions

type Profile

type Profile struct {

	// @gotags: fake:"skip"
	Id *string `protobuf:"bytes,1,opt,name=id,proto3,oneof" json:"id,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	CreatedAt *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty" fake:"skip"`
	// @gotags: fake:"{name}"
	Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty" fake:"{name}"`
	// contains filtered or unexported fields
}

func (*Profile) Descriptor deprecated

func (*Profile) Descriptor() ([]byte, []int)

Deprecated: Use Profile.ProtoReflect.Descriptor instead.

func (*Profile) GetCreatedAt

func (x *Profile) GetCreatedAt() *timestamppb.Timestamp

func (*Profile) GetId

func (x *Profile) GetId() string

func (*Profile) GetName

func (x *Profile) GetName() string

func (*Profile) GetProtoId added in v1.0.1

func (p *Profile) GetProtoId() *string

func (*Profile) GetUpdatedAt

func (x *Profile) GetUpdatedAt() *timestamppb.Timestamp

func (*Profile) MarshalJSON

func (msg *Profile) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Profile) ProtoMessage

func (*Profile) ProtoMessage()

func (*Profile) ProtoReflect

func (x *Profile) ProtoReflect() protoreflect.Message

func (*Profile) Reset

func (x *Profile) Reset()

func (*Profile) SetProtoId added in v1.0.1

func (p *Profile) SetProtoId(id string)

func (*Profile) String

func (x *Profile) String() string

func (*Profile) ToModel

func (p *Profile) ToModel() (theModel *ProfileGormModel, err error)

func (*Profile) UnmarshalJSON

func (msg *Profile) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

type ProfileGormModel

type ProfileGormModel struct {

	// @gotags: fake:"skip"
	Id *string `gorm:"type:uuid;primaryKey;default:gen_random_uuid();;" json:"id" fake:"skip"`

	// @gotags: fake:"skip"
	CreatedAt *time.Time `gorm:"type:timestamp;" json:"createdAt" fake:"skip"`

	// @gotags: fake:"skip"
	UpdatedAt *time.Time `gorm:"type:timestamp;" json:"updatedAt" fake:"skip"`

	// @gotags: fake:"{name}"
	Name string `json:"name" fake:"{name}"`
}

func (*ProfileGormModel) GetModelId added in v1.0.1

func (m *ProfileGormModel) GetModelId() *string

func (*ProfileGormModel) New added in v1.0.1

func (m *ProfileGormModel) New() interface{}

func (*ProfileGormModel) SetModelId added in v1.0.1

func (m *ProfileGormModel) SetModelId(id string)

func (*ProfileGormModel) TableName

func (m *ProfileGormModel) TableName() string

func (*ProfileGormModel) ToProto

func (m *ProfileGormModel) ToProto() (theProto *Profile, err error)

type ProfileGormModels

type ProfileGormModels []*ProfileGormModel

func (ProfileGormModels) GetByModelIds

func (m ProfileGormModels) GetByModelIds(ctx context.Context, tx *gorm.DB, preloads ...string) (err error)

func (ProfileGormModels) ToProtos

func (m ProfileGormModels) ToProtos() (protos ProfileProtos, err error)

type ProfileProtos

type ProfileProtos []*Profile

func (*ProfileProtos) GetByIds

func (p *ProfileProtos) GetByIds(ctx context.Context, tx *gorm.DB, ids []string, preloads ...string) (err error)

func (*ProfileProtos) List

func (p *ProfileProtos) List(ctx context.Context, tx *gorm.DB, limit, offset int, order interface{}, preloads ...string) (err error)

func (ProfileProtos) ToModels

func (p ProfileProtos) ToModels() (models ProfileGormModels, err error)

func (*ProfileProtos) Upsert

func (p *ProfileProtos) Upsert(ctx context.Context, tx *gorm.DB) (models ProfileGormModels, err error)

Upsert creates the protos using an on conflict clause to do updates. This function does not update *any* associations use gorm's association mode functions to update associations as you see fit after calling upsert. See https://gorm.io/docs/associations.html#Replace-Associations

type Proto added in v1.0.1

type Proto[M Models] interface {
	GetProtoId() *string
	SetProtoId(string)
	ToModel() (M, error)
}

Proto[M Models] is an interface type that defines behavior for the implementer of a given Models type

func ConvertProtoToProtosM added in v1.0.1

func ConvertProtoToProtosM[P Protos, M Models](proto interface{}) Proto[M]

ConvertProtoToProtosM converts a single proto to a Proto[M]

func ConvertProtosToProtosM added in v1.0.1

func ConvertProtosToProtosM[P Protos, M Models](protos interface{}) []Proto[M]

ConvertProtosToProtosM converts a given slice of protos into an array of the Proto interface type, which can then leverage the interface methods

type Protos added in v1.0.1

type Protos interface {
	*User | *Company | *Address | *Comment | *Profile
	GetProtoId() *string
	SetProtoId(string)
}

Protos is a union of other types that defines which types may be used in generic functions

type User

type User struct {

	// @gotags: fake:"skip"
	Id *string `protobuf:"bytes,1,opt,name=id,proto3,oneof" json:"id,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	CreatedAt string `protobuf:"bytes,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty" fake:"skip"`
	// @gotags: fake:"{price:0.00,1000.00}"
	ADouble float64 `protobuf:"fixed64,4,opt,name=a_double,json=aDouble,proto3" json:"a_double,omitempty" fake:"{price:0.00,1000.00}"`
	// @gotags: fake:"{price:0.00,1000.00}"
	AFloat float32 `protobuf:"fixed32,5,opt,name=a_float,json=aFloat,proto3" json:"a_float,omitempty" fake:"{price:0.00,1000.00}"`
	// @gotags: fake:"{int32}"
	AnInt32 int32 `protobuf:"varint,6,opt,name=an_int32,json=anInt32,proto3" json:"an_int32,omitempty" fake:"{int32}"`
	// @gotags: fake:"{number:9223372036854775807}"
	AnInt64 int64 `protobuf:"varint,7,opt,name=an_int64,json=anInt64,proto3" json:"an_int64,omitempty" fake:"{number:9223372036854775807}"`
	// @gotags: fake:"{bool}"
	ABool bool `protobuf:"varint,16,opt,name=a_bool,json=aBool,proto3" json:"a_bool,omitempty" fake:"{bool}"`
	// @gotags: fake:"{hackerphrase}"
	AString string `protobuf:"bytes,17,opt,name=a_string,json=aString,proto3" json:"a_string,omitempty" fake:"{hackerphrase}"`
	// @gotags: fake:"skip"
	ABytes []byte `protobuf:"bytes,18,opt,name=a_bytes,json=aBytes,proto3" json:"a_bytes,omitempty" fake:"skip"`
	// @gotags: fake:"{price:0.00,1000.00}"
	Doubles []float64 `protobuf:"fixed64,19,rep,packed,name=doubles,proto3" json:"doubles,omitempty" fake:"{price:0.00,1000.00}"`
	// @gotags: fake:"{price:0.00,1000.00}"
	Floats []float32 `protobuf:"fixed32,20,rep,packed,name=floats,proto3" json:"floats,omitempty" fake:"{price:0.00,1000.00}"`
	// @gotags: fake:"{int32}"
	Int32S []int32 `protobuf:"varint,21,rep,packed,name=int32s,proto3" json:"int32s,omitempty" fake:"{int32}"`
	// @gotags: fake:"{number:9223372036854775807}"
	Int64S []int64 `protobuf:"varint,22,rep,packed,name=int64s,proto3" json:"int64s,omitempty" fake:"{number:9223372036854775807}"`
	// @gotags: fake:"{bool}"
	Bools []bool `protobuf:"varint,31,rep,packed,name=bools,proto3" json:"bools,omitempty" fake:"{bool}"`
	// @gotags: fake:"{hackerphrase}"
	Strings []string `protobuf:"bytes,32,rep,name=strings,proto3" json:"strings,omitempty" fake:"{hackerphrase}"`
	// @gotags: fake:"skip"
	Bytess [][]byte `protobuf:"bytes,33,rep,name=bytess,proto3" json:"bytess,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	OptionalScalarField *string `` /* 139-byte string literal not displayed */
	// @gotags: fake:"skip"
	AStructpb *structpb.Struct `protobuf:"bytes,35,opt,name=a_structpb,json=aStructpb,proto3" json:"a_structpb,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	CompanyId *string `protobuf:"bytes,36,opt,name=companyId,proto3,oneof" json:"companyId,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	Company *Company `protobuf:"bytes,37,opt,name=company,proto3" json:"company,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	CompanyTwoId *string `protobuf:"bytes,38,opt,name=company_two_id,json=companyTwoId,proto3,oneof" json:"company_two_id,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	CompanyTwo *Company `protobuf:"bytes,39,opt,name=company_two,json=companyTwo,proto3" json:"company_two,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	AnUnexpectedId *string `protobuf:"bytes,40,opt,name=an_unexpected_id,json=anUnexpectedId,proto3,oneof" json:"an_unexpected_id,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	CompanyThree *Company `protobuf:"bytes,41,opt,name=company_three,json=companyThree,proto3" json:"company_three,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	Address *Address `protobuf:"bytes,42,opt,name=address,proto3" json:"address,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	Comments []*Comment `protobuf:"bytes,43,rep,name=comments,proto3" json:"comments,omitempty" fake:"skip"`
	// @gotags: fake:"skip"
	Profiles []*Profile `protobuf:"bytes,44,rep,name=profiles,proto3" json:"profiles,omitempty" fake:"skip"`
	// @gotags: fake:"{number:1,9}"
	IntEnum EnumOne `` /* 137-byte string literal not displayed */
	// @gotags: fake:"{number:1,9}"
	StringEnum EnumOne `` /* 146-byte string literal not displayed */
	// @gotags: fake:"{number:1,9}"
	IntEnumList []EnumOne `` /* 158-byte string literal not displayed */
	// @gotags: fake:"{number:1,9}"
	StringEnumList []EnumOne `` /* 167-byte string literal not displayed */
	// @gotags: fake:"{date:2006-01-02}"
	Date string `protobuf:"bytes,49,opt,name=date,proto3" json:"date,omitempty" fake:"{date:2006-01-02}"`
	// @gotags: fake:"{date:2006-01-02}"
	OptionalDate *string `` /* 129-byte string literal not displayed */
	// @gotags: fake:"skip"
	SomeTimestamp *timestamppb.Timestamp `protobuf:"bytes,51,opt,name=some_timestamp,json=someTimestamp,proto3" json:"some_timestamp,omitempty" fake:"skip"`
	// contains filtered or unexported fields
}

func (*User) Descriptor deprecated

func (*User) Descriptor() ([]byte, []int)

Deprecated: Use User.ProtoReflect.Descriptor instead.

func (*User) GetABool

func (x *User) GetABool() bool

func (*User) GetABytes

func (x *User) GetABytes() []byte

func (*User) GetADouble

func (x *User) GetADouble() float64

func (*User) GetAFloat

func (x *User) GetAFloat() float32

func (*User) GetAString

func (x *User) GetAString() string

func (*User) GetAStructpb

func (x *User) GetAStructpb() *structpb.Struct

func (*User) GetAddress

func (x *User) GetAddress() *Address

func (*User) GetAnInt32

func (x *User) GetAnInt32() int32

func (*User) GetAnInt64

func (x *User) GetAnInt64() int64

func (*User) GetAnUnexpectedId

func (x *User) GetAnUnexpectedId() string

func (*User) GetBools

func (x *User) GetBools() []bool

func (*User) GetBytess

func (x *User) GetBytess() [][]byte

func (*User) GetComments

func (x *User) GetComments() []*Comment

func (*User) GetCompany

func (x *User) GetCompany() *Company

func (*User) GetCompanyId added in v1.0.1

func (x *User) GetCompanyId() string

func (*User) GetCompanyThree

func (x *User) GetCompanyThree() *Company

func (*User) GetCompanyTwo

func (x *User) GetCompanyTwo() *Company

func (*User) GetCompanyTwoId

func (x *User) GetCompanyTwoId() string

func (*User) GetCreatedAt

func (x *User) GetCreatedAt() string

func (*User) GetDate added in v0.1.24

func (x *User) GetDate() string

func (*User) GetDoubles

func (x *User) GetDoubles() []float64

func (*User) GetFloats

func (x *User) GetFloats() []float32

func (*User) GetId

func (x *User) GetId() string

func (*User) GetInt32S

func (x *User) GetInt32S() []int32

func (*User) GetInt64S

func (x *User) GetInt64S() []int64

func (*User) GetIntEnum

func (x *User) GetIntEnum() EnumOne

func (*User) GetIntEnumList

func (x *User) GetIntEnumList() []EnumOne

func (*User) GetOptionalDate added in v0.1.24

func (x *User) GetOptionalDate() string

func (*User) GetOptionalScalarField

func (x *User) GetOptionalScalarField() string

func (*User) GetProfiles

func (x *User) GetProfiles() []*Profile

func (*User) GetProtoId added in v1.0.1

func (p *User) GetProtoId() *string

func (*User) GetSomeTimestamp added in v0.1.27

func (x *User) GetSomeTimestamp() *timestamppb.Timestamp

func (*User) GetStringEnum

func (x *User) GetStringEnum() EnumOne

func (*User) GetStringEnumList

func (x *User) GetStringEnumList() []EnumOne

func (*User) GetStrings

func (x *User) GetStrings() []string

func (*User) GetUpdatedAt

func (x *User) GetUpdatedAt() *timestamppb.Timestamp

func (*User) MarshalJSON

func (msg *User) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*User) ProtoMessage

func (*User) ProtoMessage()

func (*User) ProtoReflect

func (x *User) ProtoReflect() protoreflect.Message

func (*User) Reset

func (x *User) Reset()

func (*User) SetProtoId added in v1.0.1

func (p *User) SetProtoId(id string)

func (*User) String

func (x *User) String() string

func (*User) ToModel

func (p *User) ToModel() (theModel *UserGormModel, err error)

func (*User) UnmarshalJSON

func (msg *User) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

type UserGormModel

type UserGormModel struct {

	// @gotags: fake:"skip"
	Id *string `gorm:"type:uuid;primaryKey;default:gen_random_uuid();;" json:"id" fake:"skip"`

	// @gotags: fake:"skip"
	CreatedAt *time.Time `gorm:"type:timestamp;" json:"createdAt" fake:"skip"`

	// @gotags: fake:"skip"
	UpdatedAt *time.Time `gorm:"type:timestamp;" json:"updatedAt" fake:"skip"`

	// @gotags: fake:"{price:0.00,1000.00}"
	ADouble float64 `json:"aDouble" fake:"{price:0.00,1000.00}"`

	// @gotags: fake:"{price:0.00,1000.00}"
	AFloat float32 `json:"aFloat" fake:"{price:0.00,1000.00}"`

	// @gotags: fake:"{int32}"
	AnInt32 int32 `json:"anInt32" fake:"{int32}"`

	// @gotags: fake:"{number:9223372036854775807}"
	AnInt64 int64 `json:"anInt64" fake:"{number:9223372036854775807}"`

	// @gotags: fake:"{bool}"
	ABool bool `json:"aBool" fake:"{bool}"`

	// @gotags: fake:"{hackerphrase}"
	AString string `json:"aString" fake:"{hackerphrase}"`

	// @gotags: fake:"skip"
	ABytes []byte `json:"aBytes" fake:"skip"`

	// @gotags: fake:"{price:0.00,1000.00}"
	Doubles pq.Float64Array `gorm:"type:float[];" json:"doubles" fake:"{price:0.00,1000.00}"`

	// @gotags: fake:"{price:0.00,1000.00}"
	Floats pq.Float32Array `gorm:"type:float[];" json:"floats" fake:"{price:0.00,1000.00}"`

	// @gotags: fake:"{int32}"
	Int32S pq.Int32Array `gorm:"type:int[];" json:"int32s" fake:"{int32}"`

	// @gotags: fake:"{number:9223372036854775807}"
	Int64S pq.Int64Array `gorm:"type:int[];" json:"int64s" fake:"{number:9223372036854775807}"`

	// @gotags: fake:"{bool}"
	Bools pq.BoolArray `gorm:"type:bool[];" json:"bools" fake:"{bool}"`

	// @gotags: fake:"{hackerphrase}"
	Strings pq.StringArray `gorm:"type:string[];" json:"strings" fake:"{hackerphrase}"`

	// @gotags: fake:"skip"
	Bytess pq.ByteaArray `gorm:"type:bytes[];" json:"bytess" fake:"skip"`

	// @gotags: fake:"skip"
	OptionalScalarField *string `json:"optionalScalarField" fake:"skip"`

	// @gotags: fake:"skip"
	AStructpb gorm_jsonb.JSONB `gorm:"type:jsonb" json:"aStructpb" fake:"skip"`

	// @gotags: fake:"skip"
	CompanyId *string `json:"companyId" fake:"skip"`

	// @gotags: fake:"skip"
	Company *CompanyGormModel `gorm:"foreignKey:CompanyId;references:Id;constraint:OnDelete:CASCADE;" json:"company" fake:"skip"`

	// @gotags: fake:"skip"
	CompanyTwoId *string `json:"companyTwoId" fake:"skip"`

	// @gotags: fake:"skip"
	CompanyTwo *CompanyGormModel `gorm:"foreignKey:CompanyTwoId;references:Id;constraint:OnDelete:CASCADE;" json:"companyTwo" fake:"skip"`

	// @gotags: fake:"skip"
	AnUnexpectedId *string `json:"anUnexpectedId" fake:"skip"`

	// @gotags: fake:"skip"
	CompanyThree *CompanyGormModel `gorm:"foreignKey:AnUnexpectedId;references:Id;constraint:OnDelete:CASCADE;" json:"companyThree" fake:"skip"`

	// @gotags: fake:"skip"
	Address *AddressGormModel `gorm:"foreignKey:UserId;references:Id;constraint:OnDelete:CASCADE;" json:"address" fake:"skip"`

	// @gotags: fake:"skip"
	Comments []*CommentGormModel `gorm:"foreignKey:UserId;references:Id;constraint:OnDelete:CASCADE;" json:"comments" fake:"skip"`

	// @gotags: fake:"skip"
	Profiles []*ProfileGormModel `` /* 163-byte string literal not displayed */

	// @gotags: fake:"{number:1,9}"
	IntEnum int `json:"intEnum" fake:"{number:1,9}"`

	// @gotags: fake:"{number:1,9}"
	StringEnum string `json:"stringEnum" fake:"{number:1,9}"`

	// @gotags: fake:"{number:1,9}"
	IntEnumList pq.Int32Array `gorm:"type:int[];" json:"intEnumList" fake:"{number:1,9}"`

	// @gotags: fake:"{number:1,9}"
	StringEnumList pq.StringArray `gorm:"type:string[];" json:"stringEnumList" fake:"{number:1,9}"`

	// @gotags: fake:"{date:2006-01-02}"
	Date *time.Time `json:"date" fake:"{date:2006-01-02}"`

	// @gotags: fake:"{date:2006-01-02}"
	OptionalDate *time.Time `json:"optionalDate" fake:"{date:2006-01-02}"`

	// @gotags: fake:"skip"
	SomeTimestamp *time.Time `gorm:"type:timestamp;" json:"someTimestamp" fake:"skip"`
}

func (*UserGormModel) GetModelId added in v1.0.1

func (m *UserGormModel) GetModelId() *string

func (*UserGormModel) New added in v1.0.1

func (m *UserGormModel) New() interface{}

func (*UserGormModel) SetModelId added in v1.0.1

func (m *UserGormModel) SetModelId(id string)

func (*UserGormModel) TableName

func (m *UserGormModel) TableName() string

func (*UserGormModel) ToProto

func (m *UserGormModel) ToProto() (theProto *User, err error)

type UserGormModels

type UserGormModels []*UserGormModel

func (UserGormModels) GetByModelIds

func (m UserGormModels) GetByModelIds(ctx context.Context, tx *gorm.DB, preloads ...string) (err error)

func (UserGormModels) ToProtos

func (m UserGormModels) ToProtos() (protos UserProtos, err error)

type UserProtos

type UserProtos []*User

func (*UserProtos) GetByIds

func (p *UserProtos) GetByIds(ctx context.Context, tx *gorm.DB, ids []string, preloads ...string) (err error)

func (*UserProtos) List

func (p *UserProtos) List(ctx context.Context, tx *gorm.DB, limit, offset int, order interface{}, preloads ...string) (err error)

func (UserProtos) ToModels

func (p UserProtos) ToModels() (models UserGormModels, err error)

func (*UserProtos) Upsert

func (p *UserProtos) Upsert(ctx context.Context, tx *gorm.DB) (models UserGormModels, err error)

Upsert creates the protos using an on conflict clause to do updates. This function does not update *any* associations use gorm's association mode functions to update associations as you see fit after calling upsert. See https://gorm.io/docs/associations.html#Replace-Associations

Jump to

Keyboard shortcuts

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