queryutils

package
v0.0.0-...-cd06882 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package queryutils provides utilities to query the Devices table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {

	// Externally visible name. Defaults to name if not specified.
	ExternalName string

	// Defaults to ColumnTypeString.
	Type ColumnType
	// contains filtered or unexported fields
}

Column represents the schema of a Database column.

type ColumnBuilder

type ColumnBuilder struct {
	// contains filtered or unexported fields
}

func NewColumn

func NewColumn(name string) *ColumnBuilder

NewColumn starts building a new column.

func (*ColumnBuilder) Build

func (c *ColumnBuilder) Build() *Column

Build returns the built column.

func (*ColumnBuilder) WithColumnType

func (c *ColumnBuilder) WithColumnType(columnType ColumnType) *ColumnBuilder

func (*ColumnBuilder) WithExternalName

func (c *ColumnBuilder) WithExternalName(externalName string) *ColumnBuilder

func (*ColumnBuilder) WithJSONFullPath

func (c *ColumnBuilder) WithJSONFullPath(f func(fields ...string) []string) *ColumnBuilder

type ColumnType

type ColumnType int32

ColumnType is an enum for the type of a column. Valid values are in the const block above.

const (
	ColumnTypeString ColumnType = iota
	ColumnTypeJSONB
)

type Query

type Query struct {
	Statement  string
	Parameters []any
}

type QueryBuilder

type QueryBuilder struct {
	// contains filtered or unexported fields
}

QueryBuilder is a helper to create an sql query

func NewQueryBuilder

func NewQueryBuilder(t *Table) *QueryBuilder

func (*QueryBuilder) Build

func (q *QueryBuilder) Build() *Query

func (*QueryBuilder) WithCustomSelectClause

func (q *QueryBuilder) WithCustomSelectClause(selectClause string) *QueryBuilder

WithCustomSelectClause adds a custom select clause to the query.

func (*QueryBuilder) WithFromClause

func (q *QueryBuilder) WithFromClause() *QueryBuilder

WithFromClause adds a from clause to the query.

func (*QueryBuilder) WithOffsetPagination

func (q *QueryBuilder) WithOffsetPagination(offset int, pageSize int) *QueryBuilder

WithOffsetPagination adds necessary clauses to get the specific page.

func (*QueryBuilder) WithOrderByClause

func (q *QueryBuilder) WithOrderByClause(order, uniqueFieldForDeterminism string) (*QueryBuilder, error)

WithOrderByClause adds Standard SQL Order by clause, to the query including "ORDER BY" and trailing new line (if an order is specified). If no order is specified, returns "". uniqueFieldForDeterminism is a column which is unique and is always used to order with to get deterministic results: e.g. prevent getting different results for the same page.

The returned order clause is safe against SQL injection; only strings appearing from Table appear in the output.

func (*QueryBuilder) WithSelectAllClause

func (q *QueryBuilder) WithSelectAllClause() *QueryBuilder

WithSelectAllClause adds a select clause with all the columns to the query.

func (*QueryBuilder) WithSelectClause

func (q *QueryBuilder) WithSelectClause(distinct bool, columns ...*Column) *QueryBuilder

WithSelectClause adds a select clause with the specified columns to the query.

func (*QueryBuilder) WithWhereClause

func (q *QueryBuilder) WithWhereClause(filter string) (*QueryBuilder, error)

WithWhereClause adds Standard SQL WHERE clause to the query based on the filter (including "WHERE"). All field names are replaced with the safe database column names from the specified table. All user input strings are passed via query parameters, so the returned query is SQL injection safe.

type QueryParameters

type QueryParameters struct {
	// contains filtered or unexported fields
}

QueryParameters represents a collection of query parameters.

type Table

type Table struct {

	// The columns in the database table.
	Columns []*Column
	// contains filtered or unexported fields
}

Table represents the schema of a Database table.

type TableBuilder

type TableBuilder struct {
	// contains filtered or unexported fields
}

func NewTableBuilder

func NewTableBuilder(name string) *TableBuilder

NewTableBuilder starts building a new table.

func (*TableBuilder) Build

func (t *TableBuilder) Build() *Table

Build returns the built table.

func (*TableBuilder) WithColumns

func (t *TableBuilder) WithColumns(columns ...*Column) *TableBuilder

WithColumns specifies the columns in the table.

Jump to

Keyboard shortcuts

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