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

db

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 9 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 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 PtrToNullString

func PtrToNullString(p *string) sql.NullString

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 TimeToProto

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

TimeToProto converts time.Time to timestamppb.Timestamp pointer

Types

type CreateReadingParams

type CreateReadingParams struct {
	SensorID   int32     `json:"sensor_id"`
	Value      float64   `json:"value"`
	Quality    int32     `json:"quality"`
	Flagged    *bool     `json:"flagged"`
	RecordedAt time.Time `json:"recorded_at"`
}

type CreateSensorParams

type CreateSensorParams struct {
	Code         string    `json:"code"`
	Label        string    `json:"label"`
	Kind         string    `json:"kind"`
	Unit         string    `json:"unit"`
	Location     *string   `json:"location"`
	Active       *bool     `json:"active"`
	Firmware     *string   `json:"firmware"`
	SampleRateMs *int32    `json:"sample_rate_ms"`
	InstalledAt  time.Time `json:"installed_at"`
}

type DBTX

type DBTX = internal.DBTX

type GetSensorReadingStatsParams

type GetSensorReadingStatsParams = internal.GetSensorReadingStatsParams

type GetSensorReadingStatsRow

type GetSensorReadingStatsRow = internal.GetSensorReadingStatsRow

type ListReadingFilterBySensorIdRecordedAtFlaggedParams

type ListReadingFilterBySensorIdRecordedAtFlaggedParams struct {
	SensorID int32 `json:"sensor_id"`
	Flagged  bool  `json:"flagged"`
}

type ListSensorFilterByLabelKindActiveParams

type ListSensorFilterByLabelKindActiveParams struct {
	Label  string `json:"label"`
	Kind   string `json:"kind"`
	Active bool   `json:"active"`
}

type ListSensorsWithLatestReadingParams

type ListSensorsWithLatestReadingParams = internal.ListSensorsWithLatestReadingParams

type ListSensorsWithLatestReadingRow

type ListSensorsWithLatestReadingRow = internal.ListSensorsWithLatestReadingRow

type Queries

type Queries internal.Queries

func New

func New(db DBTX) *Queries

func (*Queries) CreateReading

func (q *Queries) CreateReading(ctx context.Context, arg CreateReadingParams) (int64, error)

func (*Queries) CreateSensor

func (q *Queries) CreateSensor(ctx context.Context, arg CreateSensorParams) (int32, error)

func (*Queries) DeleteReading

func (q *Queries) DeleteReading(ctx context.Context, id int64) error

func (*Queries) DeleteSensor

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

func (*Queries) GetReadingByID

func (q *Queries) GetReadingByID(ctx context.Context, id int64) (*Reading, error)

func (*Queries) GetSensorByCode

func (q *Queries) GetSensorByCode(ctx context.Context, code string) (*Sensor, error)

func (*Queries) GetSensorByID

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

func (*Queries) ListReadingBySensorId

func (q *Queries) ListReadingBySensorId(ctx context.Context, sensorID int32) ([]*Reading, error)

func (*Queries) ListReadingFilterBySensorIdRecordedAtFlagged

func (q *Queries) ListReadingFilterBySensorIdRecordedAtFlagged(ctx context.Context, arg ListReadingFilterBySensorIdRecordedAtFlaggedParams) ([]*Reading, error)

func (*Queries) ListSensorFilterByLabelKindActive

func (q *Queries) ListSensorFilterByLabelKindActive(ctx context.Context, arg ListSensorFilterByLabelKindActiveParams) ([]*Sensor, error)

func (*Queries) PruneReadingsOlderThan

func (q *Queries) PruneReadingsOlderThan(ctx context.Context, cutoff time.Time) (int64, error)

func (*Queries) UpdateReading

func (q *Queries) UpdateReading(ctx context.Context, arg UpdateReadingParams) (*Reading, error)

func (*Queries) UpdateSensor

func (q *Queries) UpdateSensor(ctx context.Context, arg UpdateSensorParams) (*Sensor, error)

func (*Queries) WithTx

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

type Reading

type Reading struct {
	ID         int64     `json:"ID"`
	SensorID   int32     `json:"sensor_id"`
	Value      float64   `json:"value"`
	Quality    int32     `json:"quality"`
	Flagged    bool      `json:"flagged"`
	RecordedAt time.Time `json:"recorded_at"`
	CreatedAt  time.Time `json:"created_at"`
}

func ReadingFromSQL

func ReadingFromSQL(db *internal.Reading) *Reading

func (*Reading) ReadingToSQL

func (m *Reading) ReadingToSQL() *internal.Reading

func (*Reading) ToProto

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

ToProto converts Reading to proto format

type Sensor

type Sensor struct {
	ID           int32     `json:"ID"`
	Code         string    `json:"code"`
	Label        string    `json:"label"`
	Kind         string    `json:"kind"`
	Unit         string    `json:"unit"`
	Location     *string   `json:"location"`
	Active       bool      `json:"active"`
	Firmware     string    `json:"firmware"`
	SampleRateMs int32     `json:"sample_rate_ms"`
	InstalledAt  time.Time `json:"installed_at"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

func SensorFromSQL

func SensorFromSQL(db *internal.Sensor) *Sensor

func (*Sensor) SensorToSQL

func (m *Sensor) SensorToSQL() *internal.Sensor

func (*Sensor) ToProto

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

ToProto converts Sensor to proto format

type UpdateReadingParams

type UpdateReadingParams struct {
	SensorID   int32     `json:"sensor_id"`
	Value      float64   `json:"value"`
	Quality    int32     `json:"quality"`
	Flagged    *bool     `json:"flagged"`
	RecordedAt time.Time `json:"recorded_at"`
	ID         int64     `json:"ID"`
}

type UpdateSensorParams

type UpdateSensorParams struct {
	Code         string  `json:"code"`
	Label        string  `json:"label"`
	Kind         string  `json:"kind"`
	Unit         string  `json:"unit"`
	Location     *string `json:"location"`
	Active       *bool   `json:"active"`
	Firmware     *string `json:"firmware"`
	SampleRateMs *int32  `json:"sample_rate_ms"`
	ID           int32   `json:"ID"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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