Documentation
¶
Index ¶
- Constants
- type Access
- type Contract
- type ContractType
- type Entity
- func (e Entity) CanFieldRead(field Field) bool
- func (e Entity) CanFieldWrite(field Field) bool
- func (e Entity) CollidableConstraints() [][]string
- func (e Entity) GetContract(contractType ContractType) (Contract, bool)
- func (e Entity) GetFieldByName(name string) (Field, bool)
- func (e Entity) GetIdField() Field
- func (e Entity) HasAutoGeneratedKey() bool
- func (e Entity) HasIdField() bool
- func (e Entity) HasPROTO() bool
- func (e Entity) HasSQLC() bool
- func (e Entity) HasUniqueConstraint(columns []string) bool
- func (e Entity) IsFieldVirtual(field Field) bool
- func (e Entity) IsPrimaryKeyField(field Field) bool
- func (e Entity) OtherCollidableConstraints(target []string) [][]string
- func (e Entity) PrimaryIndex() (Index, bool)
- func (e Entity) PrimaryKeyFields() []Field
- func (e Entity) PrimaryKeyGetQuery() (Query, bool)
- func (e Entity) ProtoQueries() []Query
- func (e Entity) QueryByType(queryType QueryType) (Query, bool)
- func (e Entity) SQLCQueries() []Query
- func (e Entity) UpsertSetFields(target []string) []Field
- func (e Entity) UpsertTarget(query Query) []string
- type Field
- type FieldType
- type Index
- type IndexColumn
- type IndexType
- type OrderColumn
- type Query
- type QueryFilter
- type QueryFilterType
- type QueryType
- type SQLDialect
- type Schema
Constants ¶
const TotalSizeColumn = "total_size"
TotalSizeColumn is the column Count() adds to a list query, named after google AIP-158
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Access ¶ added in v0.0.3
type Access string
Access narrows what a contract allows. Empty means both read and write.
type Contract ¶
type Contract struct {
Type ContractType
Access Access
}
type ContractType ¶
type ContractType string
const ( ContractSQLC ContractType = "sqlc" ContractPROTO ContractType = "proto" )
type Entity ¶
type Entity struct {
Name string
Comment string
Fields []Field
Contracts []Contract
Queries []Query
Indexes []Index
}
func FilterPROTO ¶
func FilterSQLC ¶
func (Entity) CanFieldRead ¶ added in v0.0.3
func (Entity) CanFieldWrite ¶ added in v0.0.3
func (Entity) CollidableConstraints ¶ added in v0.0.5
func (Entity) GetContract ¶ added in v0.0.3
func (e Entity) GetContract(contractType ContractType) (Contract, bool)
func (Entity) GetIdField ¶
func (Entity) HasAutoGeneratedKey ¶ added in v0.0.5
func (Entity) HasIdField ¶ added in v0.0.5
func (Entity) HasUniqueConstraint ¶ added in v0.0.5
HasUniqueConstraint reports if the columns are the primary key, a Unique() field or the columns of a Unique() index. Only such a set can be an upsert conflict target.
func (Entity) IsFieldVirtual ¶ added in v0.0.3
func (Entity) IsPrimaryKeyField ¶ added in v0.0.5
func (Entity) OtherCollidableConstraints ¶ added in v0.0.5
func (Entity) PrimaryIndex ¶ added in v0.0.5
func (Entity) PrimaryKeyFields ¶ added in v0.0.5
func (Entity) PrimaryKeyGetQuery ¶ added in v0.0.5
returns the get query keyed by the primary key
func (Entity) ProtoQueries ¶ added in v0.0.3
ProtoQueries returns the queries generated for the proto contract
func (Entity) QueryByType ¶ added in v0.0.5
returns the entity's first query of the given type
func (Entity) SQLCQueries ¶ added in v0.0.3
SQLCQueries returns the queries generated for the sqlc contract
func (Entity) UpsertSetFields ¶ added in v0.0.5
func (Entity) UpsertTarget ¶ added in v0.0.5
UpsertTarget returns the conflict target columns of an upsert query. A query that names no fields targets the primary key.
type Field ¶
type Field struct {
Name string
Type FieldType
Primary bool
Unique bool
DefaultValue any
DefaultFunc func() any
ProtoField int
Comment string
Contracts []Contract
Immutable bool
Optional bool
Validate func() any
}
func (Field) CanApiRead ¶ added in v0.0.3
func (Field) CanApiWrite ¶ added in v0.0.3
func (Field) CanDbWrite ¶ added in v0.0.3
func (Field) GetContract ¶ added in v0.0.3
func (f Field) GetContract(contractType ContractType) (Contract, bool)
GetContract returns the field contract of the given type
type Index ¶
type Index struct {
Type IndexType
Columns []IndexColumn
Unique bool
Name string
}
func (Index) FieldNames ¶
type IndexColumn ¶
type OrderColumn ¶ added in v0.0.5
type Query ¶
type Query struct {
Type QueryType
Fields []string
Filters []QueryFilter
Count bool // Count() asks for the number of matching rows
OrderBy []OrderColumn
HasLimit bool
Limit int // fixed row count, 0 means the caller sets it
HasOffset bool
Name string
Comment string
Contracts []Contract
PrimaryKey bool
Upsert bool // Upsert() updates the row the insert collides with
UpsertFields []string // the conflict target, empty means the primary key
UpsertIgnore bool // Ignore() keeps the existing row instead of updating it
}
func (Query) HasContract ¶ added in v0.0.3
func (q Query) HasContract(contractType ContractType) bool
func (Query) LimitFromRequest ¶ added in v0.0.5
type QueryFilter ¶
type QueryFilter struct {
Type QueryFilterType
Field string
Optional bool
}
type QueryFilterType ¶
type QueryFilterType string
const ( QueryFilterRange QueryFilterType = "range" QueryFilterSearch QueryFilterType = "search" QueryFilterEq QueryFilterType = "eq" )
type SQLDialect ¶
type SQLDialect string
const ( MySQL SQLDialect = "mysql" SQLite SQLDialect = "sqlite" PostgreSQL SQLDialect = "postgresql" )