Help us shape the future of Go! Take the 2026 Go Developer Survey

dbtest

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package db_test provides some helper funcs for testing db integrations

Index

Constants

This section is empty.

Variables

View Source
var (
	// NegativeInfinityTS defines a value for postgres -infinity
	NegativeInfinityTS = time.Date(math.MinInt32, time.January, 1, 0, 0, 0, 0, time.UTC)
	// PositiveInfinityTS defines a value for postgres infinity
	PositiveInfinityTS = time.Date(math.MaxInt32, time.December, 31, 23, 59, 59, 1e9-1, time.UTC)
)
View Source
var File_dbtest_storage_v1_dbtest_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Cloner

type Cloner interface {
	Clone() interface{}
}

type NotIder

type NotIder struct{}

func (*NotIder) Clone

func (i *NotIder) Clone() interface{}

type StoreTestCar

type StoreTestCar struct {

	// public_id is the used to access the car via an API
	// @inject_tag: gorm:"primaryKey;default:null"
	PublicId string `protobuf:"bytes,4,opt,name=public_id,json=publicId,proto3" json:"public_id,omitempty" gorm:"primaryKey;default:null"`
	// create_time from the RDBMS
	// @inject_tag: `gorm:"default:CURRENT_TIMESTAMP"`
	CreateTime *Timestamp `protobuf:"bytes,2,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
	// update_time from the RDBMS
	// @inject_tag: `gorm:"default:CURRENT_TIMESTAMP"`
	UpdateTime *Timestamp `protobuf:"bytes,3,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
	// name is the optional friendly name used to
	// access the Scope via an API
	// @inject_tag: `gorm:"default:null"`
	Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty" gorm:"default:null"`
	// @inject_tag: `gorm:"default:null"`
	Model string `protobuf:"bytes,6,opt,name=model,proto3" json:"model,omitempty" gorm:"default:null"`
	// @inject_tag: `gorm:"default:null"`
	Mpg int32 `protobuf:"varint,7,opt,name=mpg,proto3" json:"mpg,omitempty" gorm:"default:null"`
	// contains filtered or unexported fields
}

TestCar car model

func (*StoreTestCar) Descriptor deprecated

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

Deprecated: Use StoreTestCar.ProtoReflect.Descriptor instead.

func (*StoreTestCar) GetCreateTime

func (x *StoreTestCar) GetCreateTime() *Timestamp

func (*StoreTestCar) GetModel

func (x *StoreTestCar) GetModel() string

func (*StoreTestCar) GetMpg

func (x *StoreTestCar) GetMpg() int32

func (*StoreTestCar) GetName

func (x *StoreTestCar) GetName() string

func (*StoreTestCar) GetPublicId

func (x *StoreTestCar) GetPublicId() string

func (*StoreTestCar) GetUpdateTime

func (x *StoreTestCar) GetUpdateTime() *Timestamp

func (*StoreTestCar) ProtoMessage

func (*StoreTestCar) ProtoMessage()

func (*StoreTestCar) ProtoReflect

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

func (*StoreTestCar) Reset

func (x *StoreTestCar) Reset()

func (*StoreTestCar) String

func (x *StoreTestCar) String() string

type StoreTestRental

type StoreTestRental struct {

	// @inject_tag: `gorm:"primaryKey"`
	UserId string `protobuf:"bytes,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty" gorm:"primaryKey"`
	// @inject_tag: `gorm:"primaryKey"`
	CarId string `protobuf:"bytes,2,opt,name=car_id,json=carId,proto3" json:"car_id,omitempty" gorm:"primaryKey"`
	// create_time from the RDBMS
	// @inject_tag: `gorm:"default:CURRENT_TIMESTAMP"`
	CreateTime *Timestamp `protobuf:"bytes,3,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
	// update_time from the RDBMS
	// @inject_tag: `gorm:"default:CURRENT_TIMESTAMP"`
	UpdateTime *Timestamp `protobuf:"bytes,4,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
	// name is the optional friendly name used to
	// access the rental via an API
	// @inject_tag: `gorm:"default:null"`
	Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty" gorm:"default:null"`
	// @inject_tag: `gorm:"default:null"`
	Version uint32 `protobuf:"varint,6,opt,name=version,proto3" json:"version,omitempty" gorm:"default:null"`
	// contains filtered or unexported fields
}

TestRental for test rental model

func (*StoreTestRental) Descriptor deprecated

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

Deprecated: Use StoreTestRental.ProtoReflect.Descriptor instead.

func (*StoreTestRental) GetCarId

func (x *StoreTestRental) GetCarId() string

func (*StoreTestRental) GetCreateTime

func (x *StoreTestRental) GetCreateTime() *Timestamp

func (*StoreTestRental) GetName

func (x *StoreTestRental) GetName() string

func (*StoreTestRental) GetUpdateTime

func (x *StoreTestRental) GetUpdateTime() *Timestamp

func (*StoreTestRental) GetUserId

func (x *StoreTestRental) GetUserId() string

func (*StoreTestRental) GetVersion

func (x *StoreTestRental) GetVersion() uint32

func (*StoreTestRental) ProtoMessage

func (*StoreTestRental) ProtoMessage()

func (*StoreTestRental) ProtoReflect

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

func (*StoreTestRental) Reset

func (x *StoreTestRental) Reset()

func (*StoreTestRental) String

func (x *StoreTestRental) String() string

type StoreTestScooter

type StoreTestScooter struct {

	// private_id is the used to access scooter, but not intended to be available
	// via the API
	// @inject_tag: `gorm:"primaryKey"`
	PrivateId string `protobuf:"bytes,1,opt,name=private_id,json=privateId,proto3" json:"private_id,omitempty" gorm:"primaryKey"`
	// create_time from the RDBMS
	// @inject_tag: `gorm:"default:CURRENT_TIMESTAMP"`
	CreateTime *Timestamp `protobuf:"bytes,2,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
	// update_time from the RDBMS
	// @inject_tag: `gorm:"default:CURRENT_TIMESTAMP"`
	UpdateTime *Timestamp `protobuf:"bytes,3,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
	// @inject_tag: `gorm:"default:null"`
	Model string `protobuf:"bytes,4,opt,name=model,proto3" json:"model,omitempty" gorm:"default:null"`
	// @inject_tag: `gorm:"default:null"`
	Mpg int32 `protobuf:"varint,5,opt,name=mpg,proto3" json:"mpg,omitempty" gorm:"default:null"`
	// @inject_tag: `gorm:"-"`
	ReadOnlyField string `protobuf:"bytes,6,opt,name=read_only_field,json=readOnlyField,proto3" json:"read_only_field,omitempty" gorm:"-"`
	// contains filtered or unexported fields
}

StoreTestScooter used in the db tests only and provides a resource with a private id.

func (*StoreTestScooter) Descriptor deprecated

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

Deprecated: Use StoreTestScooter.ProtoReflect.Descriptor instead.

func (*StoreTestScooter) GetCreateTime

func (x *StoreTestScooter) GetCreateTime() *Timestamp

func (*StoreTestScooter) GetModel

func (x *StoreTestScooter) GetModel() string

func (*StoreTestScooter) GetMpg

func (x *StoreTestScooter) GetMpg() int32

func (*StoreTestScooter) GetPrivateId

func (x *StoreTestScooter) GetPrivateId() string

func (*StoreTestScooter) GetReadOnlyField

func (x *StoreTestScooter) GetReadOnlyField() string

func (*StoreTestScooter) GetUpdateTime

func (x *StoreTestScooter) GetUpdateTime() *Timestamp

func (*StoreTestScooter) ProtoMessage

func (*StoreTestScooter) ProtoMessage()

func (*StoreTestScooter) ProtoReflect

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

func (*StoreTestScooter) Reset

func (x *StoreTestScooter) Reset()

func (*StoreTestScooter) String

func (x *StoreTestScooter) String() string

type StoreTestUser

type StoreTestUser struct {

	// public_id is the used to access the user via an API
	// @inject_tag: gorm:"primaryKey;default:null"
	PublicId string `protobuf:"bytes,4,opt,name=public_id,json=publicId,proto3" json:"public_id,omitempty" gorm:"primaryKey;default:null"`
	// create_time from the RDBMS
	// @inject_tag: `gorm:"default:CURRENT_TIMESTAMP"`
	CreateTime *Timestamp `protobuf:"bytes,2,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
	// update_time from the RDBMS
	// @inject_tag: `gorm:"default:CURRENT_TIMESTAMP"`
	UpdateTime *Timestamp `protobuf:"bytes,3,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty" gorm:"default:CURRENT_TIMESTAMP"`
	// name is the optional friendly name used to
	// access the user via an API
	// @inject_tag: `gorm:"default:null"`
	Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty" gorm:"default:null"`
	// @inject_tag: `gorm:"default:null"`
	PhoneNumber string `protobuf:"bytes,6,opt,name=phone_number,json=phoneNumber,proto3" json:"phone_number,omitempty" gorm:"default:null"`
	// @inject_tag: `gorm:"default:null"`
	Email string `protobuf:"bytes,7,opt,name=email,proto3" json:"email,omitempty" gorm:"default:null"`
	// @inject_tag: `gorm:"default:null"`
	Version uint32 `protobuf:"varint,8,opt,name=version,proto3" json:"version,omitempty" gorm:"default:null"`
	// contains filtered or unexported fields
}

TestUser model

func (*StoreTestUser) Descriptor deprecated

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

Deprecated: Use StoreTestUser.ProtoReflect.Descriptor instead.

func (*StoreTestUser) GetCreateTime

func (x *StoreTestUser) GetCreateTime() *Timestamp

func (*StoreTestUser) GetEmail

func (x *StoreTestUser) GetEmail() string

func (*StoreTestUser) GetName

func (x *StoreTestUser) GetName() string

func (*StoreTestUser) GetPhoneNumber

func (x *StoreTestUser) GetPhoneNumber() string

func (*StoreTestUser) GetPublicId

func (x *StoreTestUser) GetPublicId() string

func (*StoreTestUser) GetUpdateTime

func (x *StoreTestUser) GetUpdateTime() *Timestamp

func (*StoreTestUser) GetVersion

func (x *StoreTestUser) GetVersion() uint32

func (*StoreTestUser) ProtoMessage

func (*StoreTestUser) ProtoMessage()

func (*StoreTestUser) ProtoReflect

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

func (*StoreTestUser) Reset

func (x *StoreTestUser) Reset()

func (*StoreTestUser) String

func (x *StoreTestUser) String() string

type TestCar

type TestCar struct {
	*StoreTestCar
	// contains filtered or unexported fields
}

func NewTestCar

func NewTestCar() (*TestCar, error)

func (*TestCar) SetTableName

func (c *TestCar) SetTableName(name string)

func (*TestCar) TableName

func (c *TestCar) TableName() string

type TestRental

type TestRental struct {
	*StoreTestRental
	// contains filtered or unexported fields
}

func NewTestRental

func NewTestRental(userId, carId string) (*TestRental, error)

func (*TestRental) Clone

func (t *TestRental) Clone() interface{}

Clone is useful when you're retrying transactions and you need to send the user several times

func (*TestRental) SetTableName

func (r *TestRental) SetTableName(name string)

func (*TestRental) TableName

func (r *TestRental) TableName() string

type TestScooter

type TestScooter struct {
	*StoreTestScooter
	// contains filtered or unexported fields
}

func NewTestScooter

func NewTestScooter() (*TestScooter, error)

func (*TestScooter) Clone

func (t *TestScooter) Clone() interface{}

func (*TestScooter) SetTableName

func (t *TestScooter) SetTableName(name string)

func (*TestScooter) TableName

func (t *TestScooter) TableName() string

type TestUser

type TestUser struct {
	*StoreTestUser
	// contains filtered or unexported fields
}

func AllocTestUser

func AllocTestUser() TestUser

func NewTestUser

func NewTestUser() (*TestUser, error)

func (*TestUser) Clone

func (u *TestUser) Clone() interface{}

Clone is useful when you're retrying transactions and you need to send the user several times

func (*TestUser) SetTableName

func (u *TestUser) SetTableName(name string)

func (*TestUser) TableName

func (u *TestUser) TableName() string

func (*TestUser) VetForWrite

func (u *TestUser) VetForWrite(ctx context.Context, r dbw.Reader, opType dbw.OpType, opt ...dbw.Option) error

type TestWithAfterCreate

type TestWithAfterCreate struct{}

func (*TestWithAfterCreate) AfterCreate

func (t *TestWithAfterCreate) AfterCreate(_ *gorm.DB) error

type TestWithAfterDelete

type TestWithAfterDelete struct{}

func (*TestWithAfterDelete) AfterDelete

func (t *TestWithAfterDelete) AfterDelete(_ *gorm.DB) error

type TestWithAfterFind

type TestWithAfterFind struct{}

func (*TestWithAfterFind) AfterFind

func (t *TestWithAfterFind) AfterFind(_ *gorm.DB) error

type TestWithAfterSave

type TestWithAfterSave struct{}

func (*TestWithAfterSave) AfterSave

func (t *TestWithAfterSave) AfterSave(_ *gorm.DB) error

type TestWithAfterUpdate

type TestWithAfterUpdate struct{}

func (*TestWithAfterUpdate) AfterUpdate

func (t *TestWithAfterUpdate) AfterUpdate(_ *gorm.DB) error

type TestWithBeforeCreate

type TestWithBeforeCreate struct{}

func (*TestWithBeforeCreate) BeforeCreate

func (t *TestWithBeforeCreate) BeforeCreate(_ *gorm.DB) error

type TestWithBeforeDelete

type TestWithBeforeDelete struct{}

func (*TestWithBeforeDelete) BeforeDelete

func (t *TestWithBeforeDelete) BeforeDelete(_ *gorm.DB) error

type TestWithBeforeSave

type TestWithBeforeSave struct{}

func (*TestWithBeforeSave) BeforeSave

func (t *TestWithBeforeSave) BeforeSave(_ *gorm.DB) error

type TestWithBeforeUpdate

type TestWithBeforeUpdate struct{}

func (*TestWithBeforeUpdate) BeforeUpdate

func (t *TestWithBeforeUpdate) BeforeUpdate(_ *gorm.DB) error

type Timestamp

type Timestamp struct {
	Timestamp *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// contains filtered or unexported fields
}

Timestamp for storage messages. We've defined a new local type wrapper of google.protobuf.Timestamp so we can implement sql.Scanner and sql.Valuer interfaces. See: https://golang.org/pkg/database/sql/#Scanner https://golang.org/pkg/database/sql/driver/#Valuer

func New

func New(t time.Time) *Timestamp

New constructs a new Timestamp from the provided time.Time.

func Now

func Now() *Timestamp

Now constructs a new Timestamp from the current time.

func (*Timestamp) AsTime

func (ts *Timestamp) AsTime() time.Time

AsTime converts x to a time.Time.

func (*Timestamp) Descriptor deprecated

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

Deprecated: Use Timestamp.ProtoReflect.Descriptor instead.

func (*Timestamp) GetTimestamp

func (x *Timestamp) GetTimestamp() *timestamppb.Timestamp

func (*Timestamp) GormDataType

func (ts *Timestamp) GormDataType() string

GormDataType gorm common data type (required)

func (*Timestamp) ProtoMessage

func (*Timestamp) ProtoMessage()

func (*Timestamp) ProtoReflect

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

func (*Timestamp) Reset

func (x *Timestamp) Reset()

func (*Timestamp) Scan

func (ts *Timestamp) Scan(value interface{}) error

Scan implements sql.Scanner for protobuf Timestamp.

func (*Timestamp) String

func (x *Timestamp) String() string

func (*Timestamp) Value

func (ts *Timestamp) Value() (driver.Value, error)

Scan implements driver.Valuer for protobuf Timestamp.

Jump to

Keyboard shortcuts

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