db

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MockExecuteStatement  = "UPDATE users SET name = $1 age = $2 WHERE id = $3"
	MockExecuteParameters = []any{"John", 30, 1}

	MockQueryStatement  = "SELECT * FROM users WHERE age >= $1 and age < $2 and active = $3"
	MockQueryParameters = []any{18, 21, true}

	MockQueryScalarStatement  = "SELECT COUNT(*) FROM users WHERE age >= $1 and age < $2 and active = $3"
	MockQueryScalarParameters = []any{0, 18, false}
)
View Source
var DatabaseQueryCallStack = testutils.NewCallStack()

Functions

This section is empty.

Types

type HostQueryResponse

type HostQueryResponse struct {
	Error        *string
	ResultJson   *string
	RowsAffected uint32
	LastInsertId uint64
}

type Location added in v0.17.0

type Location struct {

	// The Longitude coordinate of the location.
	Longitude float64 `json:"longitude"`

	// The Latitude coordinate of the location.
	Latitude float64 `json:"latitude"`
}

Represents a location on Earth, having longitude and latitude coordinates. Correctly serializes to and from a SQL point type, in (longitude, latitude) order.

Note that this struct is identical to the Point struct, but uses different field names.

func NewLocation added in v0.17.0

func NewLocation(longitude, latitude float64) *Location

Creates a new Location with the specified longitude and latitude coordinates.

func ParseLocation added in v0.17.0

func ParseLocation(s string) (*Location, error)

Parses a location from a string in the format "(Longitude,Latitude)" or "POINT (Longitude Latitude)".

func (*Location) MarshalJSON added in v0.17.0

func (l *Location) MarshalJSON() ([]byte, error)

func (*Location) String added in v0.17.0

func (l *Location) String() string

func (*Location) UnmarshalJSON added in v0.17.0

func (l *Location) UnmarshalJSON(data []byte) error

type Point added in v0.17.0

type Point struct {

	// The X coordinate of the point.
	X float64 `json:"x"`

	// The Y coordinate of the point.
	Y float64 `json:"y"`
}

Represents a point in 2D space, having X and Y coordinates. Correctly serializes to and from a SQL point type, in (X, Y) order.

Note that this struct is identical to the Location struct, but uses different field names.

func NewPoint added in v0.17.0

func NewPoint(x, y float64) *Point

Creates a new Point with the specified X and Y coordinates.

func ParsePoint added in v0.17.0

func ParsePoint(s string) (*Point, error)

Parses a Point from a string in the format "(X,Y)", or "POINT (X Y)".

func (*Point) MarshalJSON added in v0.17.0

func (p *Point) MarshalJSON() ([]byte, error)

func (*Point) String added in v0.17.0

func (p *Point) String() string

func (*Point) UnmarshalJSON added in v0.17.0

func (p *Point) UnmarshalJSON(data []byte) error

type QueryResponse added in v0.17.0

type QueryResponse[T any] struct {

	// The number of rows affected by the query, which typically corresponds to the number of rows returned.
	RowsAffected uint32

	// The ID of the last row inserted by the query, if applicable.
	// Note that not all databases support this feature.
	LastInsertId uint64

	// The rows returned by the query.
	Rows []T
}

Represents the result of a database query that returns rows.

func Query

func Query[T any](connection, dbType, statement string, params ...any) (*QueryResponse[T], error)

Executes a database query that returns rows. The structure of the rows is determined by the type parameter.

type Response added in v0.17.0

type Response struct {

	// The number of rows affected by the query.
	RowsAffected uint32

	// The ID of the last row inserted by the query, if applicable.
	// Note that not all databases support this feature.
	LastInsertId uint64
}

Represents the result of a database query that does not return data.

func Execute

func Execute(connection, dbType, statement string, params ...any) (*Response, error)

Executes a database query that does not return rows.

type ScalarResponse added in v0.17.0

type ScalarResponse[T any] struct {

	// The number of rows affected by the query, which is typically 1 unless the query failed,
	// or had side effects that modified more than one row.
	RowsAffected uint32

	// The ID of the last row inserted by the query, if applicable.
	// Note that not all databases support this feature.
	LastInsertId uint64

	// The scalar value returned by the query.
	Value T
}

Represents the result of a database query that returns a single scalar value.

func QueryScalar

func QueryScalar[T any](connection, dbType, statement string, params ...any) (*ScalarResponse[T], error)

Executes a database query that returns a single scalar value. The type parameter determines the type of the scalar value.

Jump to

Keyboard shortcuts

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