repository

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package repository provides a generic PostgreSQL query builder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CTEClause

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

CTEClause is a common table expression.

type DeleteQuery

type DeleteQuery[T any] struct {
	// contains filtered or unexported fields
}

DeleteQuery builds DELETE queries.

func (*DeleteQuery[T]) Execute

func (q *DeleteQuery[T]) Execute(ctx context.Context) (int64, error)

Execute runs the DELETE query.

func (*DeleteQuery[T]) OrWhere

func (q *DeleteQuery[T]) OrWhere(prop Property, op Operator, values ...any) *DeleteQuery[T]

OrWhere adds an OR condition.

func (*DeleteQuery[T]) Where

func (q *DeleteQuery[T]) Where(prop Property, op Operator, values ...any) *DeleteQuery[T]

Where adds an AND condition.

func (*DeleteQuery[T]) With

func (q *DeleteQuery[T]) With(name, sql string) *DeleteQuery[T]

With adds a CTE.

func (*DeleteQuery[T]) WithRecursive

func (q *DeleteQuery[T]) WithRecursive(name, sql string) *DeleteQuery[T]

WithRecursive adds a recursive CTE.

type InsertQuery

type InsertQuery[T any] struct {
	// contains filtered or unexported fields
}

InsertQuery builds INSERT queries.

func (*InsertQuery[T]) Execute

func (query *InsertQuery[T]) Execute(ctx context.Context) (int64, error)

Execute runs the INSERT query.

func (*InsertQuery[T]) Set

func (query *InsertQuery[T]) Set(prop Property, value any) *InsertQuery[T]

Set adds a column value.

func (*InsertQuery[T]) UpdateOnConflict

func (query *InsertQuery[T]) UpdateOnConflict(conflictCols []Property, updateCols ...Property) *InsertQuery[T]

UpdateOnConflict adds an upsert clause.

type JoinClause

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

JoinClause is a JOIN clause.

type JoinType

type JoinType uint8

JoinType is a SQL JOIN type.

const (
	Inner JoinType = iota
	Left
	Right
	Full
)

func (JoinType) String

func (jt JoinType) String() string

type Operator

type Operator uint8

Operator is a SQL comparison operator.

const (
	Equals         Operator = iota // =
	NotEquals                      // !=
	Less                           // <
	LessOrEqual                    // <=
	Greeter                        // >
	GreeterOrEqual                 // >=
	Like                           // LIKE
	ILike                          // ILIKE
	In                             // IN
	NotIn                          // NOT IN
	IsNull                         // IS NULL
	IsNotNull                      // IS NOT NULL
	RegexMatch                     // ~   (case-sensitive)
	RegexIMatch                    // ~*  (case-insensitive)
	NotRegexMatch                  // !~  (case-sensitive)
	NotRegexIMatch                 // !~* (case-insensitive)
	SimilarTo                      // SIMILAR TO
	NotSimilarTo                   // NOT SIMILAR TO
)

func (Operator) String

func (op Operator) String() string

type Property

type Property = string

Property is a column name.

type Repository

type Repository[T any] struct {
	DataSource *pgxext.DataSource
	// contains filtered or unexported fields
}

Repository builds queries for a table.

func NewRepository

func NewRepository[T any](source *pgxext.DataSource, table string) *Repository[T]

NewRepository creates a Repository.

func (*Repository[T]) Delete

func (repository *Repository[T]) Delete() *DeleteQuery[T]

Delete starts a DELETE query.

func (*Repository[T]) Insert

func (repository *Repository[T]) Insert() *InsertQuery[T]

Insert starts an INSERT query.

func (*Repository[T]) Select

func (repository *Repository[T]) Select() *SelectQuery[T]

Select starts a SELECT query.

func (*Repository[T]) Update

func (repository *Repository[T]) Update() *UpdateQuery[T]

Update starts an UPDATE query.

type SelectQuery

type SelectQuery[T any] struct {
	// contains filtered or unexported fields
}

SelectQuery builds SELECT queries.

func (*SelectQuery[T]) Count

func (query *SelectQuery[T]) Count(ctx context.Context) (int64, error)

Count returns the number of matching rows.

func (*SelectQuery[T]) Execute

func (query *SelectQuery[T]) Execute(ctx context.Context) ([]*T, error)

Execute runs the SELECT query.

func (*SelectQuery[T]) Exists

func (query *SelectQuery[T]) Exists(ctx context.Context) (bool, error)

Exists reports whether any row matches.

func (*SelectQuery[T]) First

func (query *SelectQuery[T]) First(ctx context.Context) (*T, error)

First returns the first matching row.

func (*SelectQuery[T]) FullJoin

func (query *SelectQuery[T]) FullJoin(table, on string, op Operator, value string, alias ...string) *SelectQuery[T]

FullJoin adds a FULL JOIN.

func (*SelectQuery[T]) Join

func (query *SelectQuery[T]) Join(table, on string, op Operator, value string, alias ...string) *SelectQuery[T]

Join adds an INNER JOIN.

func (*SelectQuery[T]) LeftJoin

func (query *SelectQuery[T]) LeftJoin(table, on string, op Operator, value string, alias ...string) *SelectQuery[T]

LeftJoin adds a LEFT JOIN.

func (*SelectQuery[T]) Limit

func (query *SelectQuery[T]) Limit(n uint) *SelectQuery[T]

Limit sets LIMIT.

func (*SelectQuery[T]) OrWhere

func (query *SelectQuery[T]) OrWhere(prop Property, op Operator, values ...any) *SelectQuery[T]

OrWhere adds an OR condition.

func (*SelectQuery[T]) OrderBy

func (query *SelectQuery[T]) OrderBy(prop Property, sort SortOption) *SelectQuery[T]

OrderBy sets ORDER BY.

func (*SelectQuery[T]) RightJoin

func (query *SelectQuery[T]) RightJoin(table, on string, op Operator, value string, alias ...string) *SelectQuery[T]

RightJoin adds a RIGHT JOIN.

func (*SelectQuery[T]) Where

func (query *SelectQuery[T]) Where(prop Property, op Operator, values ...any) *SelectQuery[T]

Where adds an AND condition.

func (*SelectQuery[T]) With

func (query *SelectQuery[T]) With(name, sql string) *SelectQuery[T]

With adds a CTE.

func (*SelectQuery[T]) WithRecursive

func (query *SelectQuery[T]) WithRecursive(name, sql string) *SelectQuery[T]

WithRecursive adds a recursive CTE.

type SetClause

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

SetClause is a SET assignment.

type SortOption

type SortOption uint8

SortOption is ASC or DESC.

const (
	DESC SortOption = iota
	ASC
)

func (SortOption) String

func (s SortOption) String() string

type UpdateQuery

type UpdateQuery[T any] struct {
	// contains filtered or unexported fields
}

UpdateQuery builds UPDATE queries.

func (*UpdateQuery[T]) Execute

func (query *UpdateQuery[T]) Execute(ctx context.Context) (int64, error)

Execute runs the UPDATE query.

func (*UpdateQuery[T]) OrWhere

func (query *UpdateQuery[T]) OrWhere(prop Property, op Operator, values ...any) *UpdateQuery[T]

OrWhere adds an OR condition.

func (*UpdateQuery[T]) Set

func (query *UpdateQuery[T]) Set(prop Property, value any) *UpdateQuery[T]

Set adds an assignment.

func (*UpdateQuery[T]) Where

func (query *UpdateQuery[T]) Where(prop Property, op Operator, values ...any) *UpdateQuery[T]

Where adds an AND condition.

func (*UpdateQuery[T]) With

func (query *UpdateQuery[T]) With(name, sql string) *UpdateQuery[T]

With adds a CTE.

func (*UpdateQuery[T]) WithRecursive

func (query *UpdateQuery[T]) WithRecursive(name, sql string) *UpdateQuery[T]

WithRecursive adds a recursive CTE.

type WhereClause

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

WhereClause is a WHERE condition.

Jump to

Keyboard shortcuts

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