query

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package query holds the query builders used in an entity schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListByOperations

type ListByOperations interface {
	QueryBuilder
	// Count also returns the number of matching rows.
	Count() ListByOperations
	// OrderBy sorts the result by the given field.
	OrderBy(field string) ListByOperations
	// Name overrides the auto-generated query/method name
	Name(name string) ListByOperations
	// Contracts limits the query to the given layers, sqlc or proto.
	Contracts(contracts ...entlite.Layer) ListByOperations
}

ListByOperations exposes the modifiers available on a ListBy query.

func ListBy

func ListBy(args ...interface{}) ListByOperations

ListBy lists records with filters. Takes field names, which default to Eq, or Filter values, e.g. ListBy("org_id") or ListBy(filter.Range("age"), filter.Search("name"))

type Query

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

Query holds the state of one query.

func (Query) Contracts added in v0.0.3

func (q Query) Contracts(contracts ...entlite.Layer) QueryOperations

Contracts limits the query to the given layers, sqlc or proto.

func (Query) GetContracts added in v0.0.3

func (q Query) GetContracts() []entlite.Layer

GetContracts returns the layers the query belongs to.

func (Query) GetFields

func (q Query) GetFields() []string

GetFields returns the fields of a GetBy query.

func (Query) GetFilters

func (q Query) GetFilters() []filter.Filter

GetFilters returns the filters of a ListBy query.

func (Query) GetName

func (q Query) GetName() string

GetName returns the custom query name, or "" when auto-generated.

func (Query) GetOrderBy

func (q Query) GetOrderBy() string

GetOrderBy returns the order by field, or "" when there is none.

func (Query) GetType

func (q Query) GetType() Type

GetType returns the query kind.

func (Query) HasCount

func (q Query) HasCount() bool

HasCount reports if a ListBy query also returns a count.

func (Query) Name

func (q Query) Name(name string) QueryOperations

Name overrides the auto-generated query/method name

func (Query) Query

func (Query) Query()

marker method for sealed interface

type QueryBuilder

type QueryBuilder interface {
	Query()
}

QueryBuilder is implemented by every query.

func DefaultCRUD

func DefaultCRUD() QueryBuilder

DefaultCRUD expands to several queries, so it cannot be named

type QueryOperations

type QueryOperations interface {
	QueryBuilder
	// Name overrides the auto-generated query/method name
	Name(name string) QueryOperations
	// Contracts limits the query to the given layers, sqlc or proto.
	Contracts(contracts ...entlite.Layer) QueryOperations
}

QueryOperations exposes the modifiers available on a plain query.

func Create

func Create() QueryOperations

Create inserts one record.

func CreateBulk

func CreateBulk() QueryOperations

CreateBulk inserts many records in one call.

func Delete

func Delete() QueryOperations

Delete deletes one record by primary key.

func DeleteAll

func DeleteAll() QueryOperations

DeleteAll deletes every record of the table.

func Get

func Get() QueryOperations

Get reads one record by primary key.

func GetBy

func GetBy(fields ...string) QueryOperations

GetBy gets a record by one or more fields, e.g. GetBy("id") or GetBy("org_id", "email")

func ListAll

func ListAll() QueryOperations

ListAll reads every record of the table.

func Update

func Update() QueryOperations

Update updates one record by primary key.

type Type

type Type string

Type tells which kind of query is described.

const (
	// TypeDefaultCRUD expands to the common create, read, update and delete queries.
	TypeDefaultCRUD Type = "default_crud"
	// TypeCreate inserts one row.
	TypeCreate Type = "create"
	// TypeCreateBulk inserts many rows in one call.
	TypeCreateBulk Type = "create_bulk"
	// TypeGet reads one row by primary key.
	TypeGet Type = "get"
	// TypeUpdate updates one row by primary key.
	TypeUpdate Type = "update"
	// TypeDelete deletes one row by primary key.
	TypeDelete Type = "delete"
	// TypeDeleteAll deletes every row of the table.
	TypeDeleteAll Type = "delete_all"
	// TypeListAll reads every row of the table.
	TypeListAll Type = "list_all"
	// TypeGetBy reads one row by the given fields.
	TypeGetBy Type = "get_by"
	// TypeListBy reads many rows by the given filters.
	TypeListBy Type = "list_by"
)

Jump to

Keyboard shortcuts

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