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: 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 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 CreateSensorReadingParams added in v0.0.6

type CreateSensorReadingParams 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 DBTX

type DBTX = internal.DBTX

type GetSensorReadingStatsParams

type GetSensorReadingStatsParams = internal.GetSensorReadingStatsParams

type GetSensorReadingStatsRow

type GetSensorReadingStatsRow = internal.GetSensorReadingStatsRow

type ListSensorFilterByLabelKindActiveParams

type ListSensorFilterByLabelKindActiveParams struct {
	Label  string `json:"label"`
	Kind   string `json:"kind"`
	Active bool   `json:"active"`
	Offset int32  `json:"offset"`
	Limit  int32  `json:"limit"`
}

type ListSensorFilterByLabelKindActiveRow added in v0.0.5

type ListSensorFilterByLabelKindActiveRow = internal.ListSensorFilterByLabelKindActiveRow

type ListSensorReadingBySensorIdParams added in v0.0.6

type ListSensorReadingBySensorIdParams struct {
	SensorID int32 `json:"sensor_id"`
	Offset   int32 `json:"offset"`
	Limit    int32 `json:"limit"`
}

type ListSensorReadingFilterBySensorIdRecordedAtFlaggedParams added in v0.0.6

type ListSensorReadingFilterBySensorIdRecordedAtFlaggedParams struct {
	SensorID      int32     `json:"sensor_id"`
	MinRecordedAt time.Time `json:"min_recorded_at"`
	MaxRecordedAt time.Time `json:"max_recorded_at"`
	Flagged       bool      `json:"flagged"`
	Offset        int32     `json:"offset"`
	Limit         int32     `json:"limit"`
}

type ListSensorReadingFilterBySensorIdRecordedAtFlaggedRow added in v0.0.6

type ListSensorReadingFilterBySensorIdRecordedAtFlaggedRow = internal.ListSensorReadingFilterBySensorIdRecordedAtFlaggedRow

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) CreateSensor

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

func (*Queries) CreateSensorReading added in v0.0.6

func (q *Queries) CreateSensorReading(ctx context.Context, arg CreateSensorReadingParams) (int64, error)

func (*Queries) DeleteSensor

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

func (*Queries) DeleteSensorReading added in v0.0.6

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

func (*Queries) GetSensorByCode

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

func (*Queries) GetSensorById added in v0.0.6

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

func (*Queries) GetSensorReadingById added in v0.0.6

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

func (*Queries) ListSensorFilterByLabelKindActive

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

func (*Queries) ListSensorReadingBySensorId added in v0.0.6

func (q *Queries) ListSensorReadingBySensorId(ctx context.Context, arg ListSensorReadingBySensorIdParams) ([]*SensorReading, error)

func (*Queries) ListSensorReadingFilterBySensorIdRecordedAtFlagged added in v0.0.6

func (q *Queries) ListSensorReadingFilterBySensorIdRecordedAtFlagged(ctx context.Context, arg ListSensorReadingFilterBySensorIdRecordedAtFlaggedParams) ([]*SensorReading, int64, error)

func (*Queries) PruneReadingsOlderThan

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

func (*Queries) UpdateSensor

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

func (*Queries) UpdateSensorReading added in v0.0.6

func (q *Queries) UpdateSensorReading(ctx context.Context, arg UpdateSensorReadingParams) (*SensorReading, error)

func (*Queries) WithTx

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

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 SensorReading added in v0.0.6

type SensorReading 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 SensorReadingFromSQL added in v0.0.6

func SensorReadingFromSQL(db *internal.SensorReading) *SensorReading

func (*SensorReading) SensorReadingToSQL added in v0.0.6

func (m *SensorReading) SensorReadingToSQL() *internal.SensorReading

func (*SensorReading) ToProto added in v0.0.6

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

ToProto converts SensorReading to proto format

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"`
}

type UpdateSensorReadingParams added in v0.0.6

type UpdateSensorReadingParams 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"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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