query

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get[T any](v *T) T

Get removes the pointer used when [goe.Select] get any argument.

Example

for row, err := range goe.Select(&struct {
	User    *string //goe needs a pointer for store the referecent argument
	Role    *string //goe needs a pointer for store the referecent argument
	EndTime **time.Time //if the argument is already a pointer goe needs a pointer to a pointer for store the referecent argument
}{
	User:    &db.User.Name,
	Role:    &db.Role.Name,
	EndTime: &db.UserRole.EndDate,
}).
From(db.User).
Joins(
	join.LeftJoin[int](&db.User.Id, &db.UserRole.UserId),
	join.LeftJoin[int](&db.UserRole.RoleId, &db.Role.Id),
).
OrderByAsc(&db.User.Id).Rows() {
	q = append(q, struct {
		User    string //return model can be different from select model
		Role    string
		EndTime *time.Time
	}{
		User:    query.Get(row.User), //get a empty string if the database returns null
		Role:    query.Get(row.Role), //get a empty string if the database returns null
		EndTime: query.Get(row.EndTime), //EndTime can store nil/null values
	})
}

Types

type Count

type Count struct {
	Field any
	Value int64
}

func (Count) Aggregate

func (c Count) Aggregate() enum.AggregateType

func (*Count) Scan

func (c *Count) Scan(src any) error

type Function

type Function[T any] struct {
	Field *T
	Type  enum.FunctionType
	Value T
}

func (Function[T]) GetType

func (f Function[T]) GetType() enum.FunctionType

func (Function[T]) GetValue

func (f Function[T]) GetValue() any

func (*Function[T]) Scan

func (f *Function[T]) Scan(src any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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