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

db

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntConvert

func IntConvert[From, To ~int | ~int8 | ~int16 | ~int32 | ~int64 |
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
	~float32 | ~float64](src From) To

func IntPtrConvert

func IntPtrConvert[From, To ~int | ~int32 | ~int64 | ~float32 | ~float64](src *From) *To

example: IntPtrConvert[int64, int32](dbRow.Age)

func NullBoolToPtr

func NullBoolToPtr(n sql.NullBool) *bool

func NullBytesToPtr

func NullBytesToPtr(b []byte) *[]byte

--- Bytes Converters ---

func NullFloat64ToPtr

func NullFloat64ToPtr(n sql.NullFloat64) *float64

func NullInt32ToPtr

func NullInt32ToPtr(n sql.NullInt32) *int32

--- Nullable SQL Type Converters ---

func NullInt64ToPtr

func NullInt64ToPtr(n sql.NullInt64) *int64

func NullRawMessageToPtr added in v0.0.4

func NullRawMessageToPtr(n pqtype.NullRawMessage) *string

func NullStringToPtr

func NullStringToPtr(n sql.NullString) *string

func NullTimeToProto

func NullTimeToProto(n sql.NullTime) *timestamppb.Timestamp

--- Time Converters ---

func OptionalWithFallback

func OptionalWithFallback[T any](val *T, fallback T) T

OptionalWithFallback chooses fallback if optional value is nil

func ProtoToNullTime

func ProtoToNullTime(t *timestamppb.Timestamp) sql.NullTime

func ProtoToTime

func ProtoToTime(t *timestamppb.Timestamp) time.Time

A nil pointer returns a zero time.Time{}

func PtrBytesToNullString

func PtrBytesToNullString(p *[]byte) sql.NullString

PtrBytesToNullString converts *[]byte to sql.NullString for MySQL compatibility

func PtrToNullBool

func PtrToNullBool(p *bool) sql.NullBool

func PtrToNullBytes

func PtrToNullBytes(b *[]byte) []byte

func PtrToNullFloat64

func PtrToNullFloat64(p *float64) sql.NullFloat64

func PtrToNullInt32

func PtrToNullInt32(p *int32) sql.NullInt32

func PtrToNullInt64

func PtrToNullInt64(p *int64) sql.NullInt64

func PtrToNullRawMessage added in v0.0.4

func PtrToNullRawMessage(p *string) pqtype.NullRawMessage

postgres keeps a nullable JSONB column as pqtype.NullRawMessage

func PtrToNullString

func PtrToNullString(p *string) sql.NullString

func RawMessageToString added in v0.0.4

func RawMessageToString(r json.RawMessage) string

func SQLiteBoolPtrToInt64Ptr

func SQLiteBoolPtrToInt64Ptr(b *bool) *int64

SQLiteBoolPtrToInt64Ptr converts *bool to *int64 for nullable columns via sqlc.narg

func SQLiteBoolToInt

func SQLiteBoolToInt(b bool) int64

func SQLiteInt64PtrToBoolPtr

func SQLiteInt64PtrToBoolPtr(i *int64) *bool

SQLiteInt64PtrToBoolPtr is the inverse of SQLiteBoolPtrToInt64Ptr.

func SQLiteIntToBool

func SQLiteIntToBool(i int64) bool

--- SQLite bool converters ---

func StringToRawMessage added in v0.0.4

func StringToRawMessage(s string) json.RawMessage

--- JSON Converters --- postgres JSONB and mysql JSON come out of sqlc as json.RawMessage

func TimeToProto

func TimeToProto(t time.Time) *timestamppb.Timestamp

TimeToProto converts time.Time to timestamppb.Timestamp pointer

Types

type CreateBulkUserParams

type CreateBulkUserParams struct {
	Email       string   `json:"email"`
	Name        string   `json:"name"`
	Age         *int32   `json:"age"`
	Password    string   `json:"password"`
	ApiKey      *[]byte  `json:"api_key"`
	IsActive    *bool    `json:"is_active"`
	LoginCount  *int64   `json:"login_count"`
	Rating      *float64 `json:"rating"`
	Preferences *string  `json:"preferences"`
}

type CreateUserParams

type CreateUserParams struct {
	Email       string   `json:"email"`
	Name        string   `json:"name"`
	Age         *int32   `json:"age"`
	Password    string   `json:"password"`
	ApiKey      *[]byte  `json:"api_key"`
	IsActive    *bool    `json:"is_active"`
	LoginCount  *int64   `json:"login_count"`
	Rating      *float64 `json:"rating"`
	Preferences *string  `json:"preferences"`
}

type DBTX

type DBTX = internal.DBTX

type ListActiveParams added in v0.0.4

type ListActiveParams struct {
	IsActive bool  `json:"is_active"`
	Offset   int32 `json:"offset"`
	Limit    int32 `json:"limit"`
}

type ListUserFilterByAgeNameParams

type ListUserFilterByAgeNameParams struct {
	MinAge *int32 `json:"min_age"`
	MaxAge *int32 `json:"max_age"`
	Name   string `json:"name"`
	Offset int32  `json:"offset"`
	Limit  int32  `json:"limit"`
}

type ListUserFilterByAgeNameRow added in v0.0.5

type ListUserFilterByAgeNameRow = internal.ListUserFilterByAgeNameRow

type Queries

type Queries internal.Queries

func New

func New(db DBTX) *Queries

func (*Queries) CreateBulkUser

func (q *Queries) CreateBulkUser(ctx context.Context, args []CreateBulkUserParams) ([]int32, error)

func (*Queries) CreateUser

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (int32, error)

func (*Queries) DeleteAllUser

func (q *Queries) DeleteAllUser(ctx context.Context) error

func (*Queries) DeleteUser

func (q *Queries) DeleteUser(ctx context.Context, id int32) error

func (*Queries) GetUserByEmail

func (q *Queries) GetUserByEmail(ctx context.Context, email string) (*User, error)

func (*Queries) GetUserById added in v0.0.6

func (q *Queries) GetUserById(ctx context.Context, id int32) (*User, error)

func (*Queries) ListActive

func (q *Queries) ListActive(ctx context.Context, arg ListActiveParams) ([]*User, error)

func (*Queries) ListAllUser

func (q *Queries) ListAllUser(ctx context.Context) ([]*User, error)

func (*Queries) ListUserFilterByAgeName

func (q *Queries) ListUserFilterByAgeName(ctx context.Context, arg ListUserFilterByAgeNameParams) ([]*User, int64, error)

func (*Queries) UpdateUser

func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (*User, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx *sql.Tx) *Queries

type UpdateUserParams

type UpdateUserParams struct {
	Email       string   `json:"email"`
	Name        string   `json:"name"`
	Age         *int32   `json:"age"`
	Password    *string  `json:"password"`
	IsActive    *bool    `json:"is_active"`
	LoginCount  *int64   `json:"login_count"`
	Rating      *float64 `json:"rating"`
	Preferences *string  `json:"preferences"`
	ID          int32    `json:"id"`
}

type User

type User struct {
	ID          int32     `json:"id"`
	Email       string    `json:"email"`
	Name        string    `json:"name"`
	Age         *int32    `json:"age"`
	Password    string    `json:"password"`
	ApiKey      []byte    `json:"api_key"`
	IsActive    bool      `json:"is_active"`
	LoginCount  int64     `json:"login_count"`
	Rating      float64   `json:"rating"`
	Preferences string    `json:"preferences"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func UserFromSQL

func UserFromSQL(db *internal.User) *User

func (*User) ToProto

func (m *User) ToProto() *pb.User

ToProto converts User to proto format

func (*User) UserToSQL

func (m *User) UserToSQL() *internal.User

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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