Documentation ¶
Index ¶
- Variables
- func AuthoriseAction(scope *Scope, input map[string]any, rowsToAuthorise []map[string]any) (authorised bool, err error)
- func AuthoriseForActionType(scope *Scope, opType proto.ActionType, rowsToAuthorise []map[string]any) (authorised bool, err error)
- func Create(scope *Scope, input map[string]any) (res map[string]any, err error)
- func CreateIdentity(ctx context.Context, schema *proto.Schema, email string, password string, ...) (*auth.Identity, error)
- func CreateIdentityWithIdTokenClaims(ctx context.Context, schema *proto.Schema, externalId string, issuer string, ...) (*auth.Identity, error)
- func Delete(scope *Scope, input map[string]any) (res *string, err error)
- func Execute(scope *Scope, inputs any) (result any, meta *common.ResponseMetadata, err error)
- func FindIdentityByEmail(ctx context.Context, schema *proto.Schema, email string, issuer string) (*auth.Identity, error)
- func FindIdentityByExternalId(ctx context.Context, schema *proto.Schema, externalId string, issuer string) (*auth.Identity, error)
- func FindIdentityById(ctx context.Context, schema *proto.Schema, id string) (*auth.Identity, error)
- func GenerateListStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, *Page, error)
- func Get(scope *Scope, input map[string]any) (map[string]any, error)
- func HandleAuthorizationHeader(ctx context.Context, schema *proto.Schema, headers http.Header) (*auth.Identity, error)
- func HandleBearerToken(ctx context.Context, schema *proto.Schema, token string) (*auth.Identity, error)
- func List(scope *Scope, input map[string]any) (map[string]any, error)
- func ResetPassword(scope *Scope, input map[string]any) errordeprecated
- func ResetRequestPassword(scope *Scope, input map[string]any) error
- func TryResolveAuthorisationEarly(scope *Scope, permissions []*proto.PermissionRule) (canResolveAll bool, authorised bool, err error)
- func Update(scope *Scope, input map[string]any) (res map[string]any, err error)
- func UpdateIdentityWithIdTokenClaims(ctx context.Context, schema *proto.Schema, externalId string, issuer string, ...) (*auth.Identity, error)
- type ActionOperator
- type ExternalUserDetails
- type JoinOption
- type JoinType
- type Page
- type PageInfo
- type QueryBuilder
- func (query *QueryBuilder) AddWriteValue(operand *QueryOperand, value *QueryOperand)
- func (query *QueryBuilder) AddWriteValues(values map[string]*QueryOperand)
- func (query *QueryBuilder) And()
- func (query *QueryBuilder) AppendDistinctOn(operand *QueryOperand)
- func (query *QueryBuilder) AppendOrderBy(operand *QueryOperand, direction string)
- func (query *QueryBuilder) AppendReturning(operand *QueryOperand)
- func (query *QueryBuilder) AppendSelect(operand *QueryOperand)
- func (query *QueryBuilder) AppendSelectClause(clause string)
- func (query *QueryBuilder) ApplyPaging(page Page) error
- func (query *QueryBuilder) CloseParenthesis()
- func (query *QueryBuilder) Copy() *QueryBuilder
- func (query *QueryBuilder) DeleteStatement(ctx context.Context) *Statement
- func (query *QueryBuilder) InsertStatement(ctx context.Context) *Statement
- func (query *QueryBuilder) Join(joinModel string, joinField *QueryOperand, modelField *QueryOperand)
- func (query *QueryBuilder) Limit(limit int)
- func (query *QueryBuilder) OpenParenthesis()
- func (query *QueryBuilder) Or()
- func (query *QueryBuilder) SelectStatement() *Statement
- func (query *QueryBuilder) UpdateStatement(ctx context.Context) *Statement
- func (query *QueryBuilder) Where(left *QueryOperand, operator ActionOperator, right *QueryOperand) error
- type QueryBuilderOption
- type QueryOperand
- func AllFields() *QueryOperand
- func ExpressionField(fragments []string, field string) *QueryOperand
- func Field(field string) *QueryOperand
- func IdField() *QueryOperand
- func InlineQuery(query *QueryBuilder, column *QueryOperand) *QueryOperand
- func Null() *QueryOperand
- func Raw(sql string) *QueryOperand
- func Value(value any) *QueryOperand
- type Relationship
- type Row
- type Rows
- type Scope
- type Statement
- func GenerateCreateStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)
- func GenerateDeleteStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)
- func GenerateGetStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)
- func GeneratePermissionStatement(scope *Scope, permissions []*proto.PermissionRule, input map[string]any, ...) (*Statement, error)
- func GenerateUpdateStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)
- func (statement *Statement) Execute(ctx context.Context) (int, error)
- func (statement *Statement) ExecuteToMany(ctx context.Context, page *Page) (Rows, *PageInfo, error)
- func (statement *Statement) ExecuteToSingle(ctx context.Context) (map[string]any, error)
- func (statement *Statement) SqlArgs() []any
- func (statement *Statement) SqlTemplate() string
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidToken = common.NewAuthenticationFailedMessageErr("cannot be parsed or verified as a valid JWT") ErrTokenExpired = common.NewAuthenticationFailedMessageErr("token has expired") ErrIdentityNotFound = common.NewAuthenticationFailedMessageErr("identity not found") )
Functions ¶
func AuthoriseAction ¶
func AuthoriseAction(scope *Scope, input map[string]any, rowsToAuthorise []map[string]any) (authorised bool, err error)
AuthoriseAction checks authorisation for rows using the permission and role rules applicable for an action, which could be defined at model- and action- levels.
func AuthoriseForActionType ¶
func AuthoriseForActionType(scope *Scope, opType proto.ActionType, rowsToAuthorise []map[string]any) (authorised bool, err error)
AuthoriseForActionType checks authorisation for rows using permission and role rules defined for some action type, i.e. agnostic to any action.
func CreateIdentity ¶
func CreateIdentityWithIdTokenClaims ¶ added in v0.372.0
func FindIdentityByEmail ¶
func FindIdentityById ¶
func GenerateListStatement ¶
func HandleBearerToken ¶
func ResetPassword
deprecated
func TryResolveAuthorisationEarly ¶
func TryResolveAuthorisationEarly(scope *Scope, permissions []*proto.PermissionRule) (canResolveAll bool, authorised bool, err error)
TryResolveAuthorisationEarly will attempt to check authorisation early without row-based querying. This will take into account logical conditions and multiple expression and role permission attributes.
Types ¶
type ActionOperator ¶
type ActionOperator int
An ActionOperator gives a symbolic, machine-readable name to each of the comparison operators that Keel Actions work with at a CONCEPTUAL level.
By design, the ActionOperator has no knowledge (in of itself) of how these might be expressed in schema's or in request inputs, or in expressions for example.
const ( Unknown ActionOperator = iota After Before Contains Equals EndsWith GreaterThan GreaterThanEquals LessThan LessThanEquals NotContains NotEquals NotOneOf OneOf OnOrAfter OnOrBefore StartsWith )
type ExternalUserDetails ¶
type JoinOption ¶
type JoinOption struct {
Type JoinType
}
type Page ¶
A Page describes which page you want from a list of records, in the style of this "Connection" pattern: https://relay.dev/graphql/connections.htm
Consider for example, that you previously fetched a page of 10 records and from that previous response you also knew that the last of those 10 records could be referred to with the opaque cursor "abc123". Armed with that information you can ask for the next page of 10 records by setting First to 10, and After to "abc123".
To move backwards, you'd set the Last and Before fields instead.
When you have no prior positional context you should specify First but leave Before and After to the empty string. This gives you the first N records.
func ParsePage ¶
ParsePage extracts page mandate information from the given map and uses it to compose a Page.
func (*Page) Cursor ¶ added in v0.383.0
Cursor returns the cursor used in the pagination based on the direction of pagination: - if backwards, it's `before` - if forward pagination, it's `after`
func (*Page) IsBackwards ¶ added in v0.383.0
IsBackwards tells us if the page is backwards paginated (e.g. we're requesting elements before a cursor)
type PageInfo ¶
type PageInfo struct { // Count returns the number of rows returned for the current page Count int // TotalCount returns the total number of rows across all pages TotalCount int // HasNextPage indicates if there is a subsequent page after the current page HasNextPage bool // StartCursor is the identifier representing the first row in the set StartCursor string // EndCursor is the identifier representing the last row in the set EndCursor string }
type QueryBuilder ¶
type QueryBuilder struct { // The base model this query builder is acting on. Model *proto.Model // contains filtered or unexported fields }
func NewQuery ¶
func NewQuery(model *proto.Model, opts ...QueryBuilderOption) *QueryBuilder
func (*QueryBuilder) AddWriteValue ¶
func (query *QueryBuilder) AddWriteValue(operand *QueryOperand, value *QueryOperand)
Includes a value to be written during an INSERT or UPDATE.
func (*QueryBuilder) AddWriteValues ¶
func (query *QueryBuilder) AddWriteValues(values map[string]*QueryOperand)
Includes values to be written during an INSERT or UPDATE.
func (*QueryBuilder) And ¶
func (query *QueryBuilder) And()
Appends the next condition with a logical AND.
func (*QueryBuilder) AppendDistinctOn ¶
func (query *QueryBuilder) AppendDistinctOn(operand *QueryOperand)
Include a column in this table in DISTINCT ON.
func (*QueryBuilder) AppendOrderBy ¶
func (query *QueryBuilder) AppendOrderBy(operand *QueryOperand, direction string)
Include a column in ORDER BY. If the column already exists, then just update the sort direction.
func (*QueryBuilder) AppendReturning ¶
func (query *QueryBuilder) AppendReturning(operand *QueryOperand)
Include a column in RETURNING.
func (*QueryBuilder) AppendSelect ¶
func (query *QueryBuilder) AppendSelect(operand *QueryOperand)
Includes a column in SELECT.
func (*QueryBuilder) AppendSelectClause ¶
func (query *QueryBuilder) AppendSelectClause(clause string)
Include a clause in SELECT.
func (*QueryBuilder) ApplyPaging ¶
func (query *QueryBuilder) ApplyPaging(page Page) error
Apply pagination filters to the query.
func (*QueryBuilder) CloseParenthesis ¶
func (query *QueryBuilder) CloseParenthesis()
Closes the current conditional scope in the where expression (i.e. close parethesis).
func (*QueryBuilder) Copy ¶
func (query *QueryBuilder) Copy() *QueryBuilder
Creates a copy of the query builder.
func (*QueryBuilder) DeleteStatement ¶
func (query *QueryBuilder) DeleteStatement(ctx context.Context) *Statement
Generates an executable DELETE statement with the list of arguments.
func (*QueryBuilder) InsertStatement ¶
func (query *QueryBuilder) InsertStatement(ctx context.Context) *Statement
Generates an executable INSERT statement with the list of arguments.
func (*QueryBuilder) Join ¶
func (query *QueryBuilder) Join(joinModel string, joinField *QueryOperand, modelField *QueryOperand)
Include an JOIN clause.
func (*QueryBuilder) OpenParenthesis ¶
func (query *QueryBuilder) OpenParenthesis()
Opens a new conditional scope in the where expression (i.e. open parethesis).
func (*QueryBuilder) Or ¶
func (query *QueryBuilder) Or()
Appends the next condition with a logical OR.
func (*QueryBuilder) SelectStatement ¶
func (query *QueryBuilder) SelectStatement() *Statement
Generates an executable SELECT statement with the list of arguments.
func (*QueryBuilder) UpdateStatement ¶
func (query *QueryBuilder) UpdateStatement(ctx context.Context) *Statement
Generates an executable UPDATE statement with the list of arguments.
func (*QueryBuilder) Where ¶
func (query *QueryBuilder) Where(left *QueryOperand, operator ActionOperator, right *QueryOperand) error
Include a WHERE condition, ANDed to the existing filters (unless an OR has been specified)
type QueryBuilderOption ¶
type QueryBuilderOption func(qb *QueryBuilder)
func WithJoinType ¶
func WithJoinType(joinType JoinType) QueryBuilderOption
type QueryOperand ¶
type QueryOperand struct {
// contains filtered or unexported fields
}
func ExpressionField ¶
func ExpressionField(fragments []string, field string) *QueryOperand
Some field from the fragments of an expression or input.
func InlineQuery ¶
func InlineQuery(query *QueryBuilder, column *QueryOperand) *QueryOperand
Represents an inline query. column refers to the single column to select from the inline query statement.
func (*QueryOperand) IsField ¶
func (o *QueryOperand) IsField() bool
func (*QueryOperand) IsInlineQuery ¶
func (o *QueryOperand) IsInlineQuery() bool
A query builder to be evaluated and injected as an operand.
func (*QueryOperand) IsNull ¶
func (o *QueryOperand) IsNull() bool
func (*QueryOperand) IsRaw ¶ added in v0.369.1
func (o *QueryOperand) IsRaw() bool
Raw SQL to be used as a operand.
func (*QueryOperand) IsValue ¶
func (o *QueryOperand) IsValue() bool
type Relationship ¶
type Relationship struct {
// contains filtered or unexported fields
}
type Scope ¶
type Scope struct { Context context.Context Action *proto.Action Model *proto.Model Job *proto.Job Schema *proto.Schema }
func NewJobScope ¶
func NewModelScope ¶
type Statement ¶
type Statement struct {
// contains filtered or unexported fields
}
The templated SQL statement and associated values, ready to be executed.
func GenerateCreateStatement ¶
func GenerateDeleteStatement ¶
func GenerateGetStatement ¶
func GenerateUpdateStatement ¶
func (*Statement) Execute ¶
Execute the SQL statement against the database, returning the number of rows affected.
func (*Statement) ExecuteToMany ¶
Execute the SQL statement against the database, return the rows, number of rows affected, and a boolean to indicate if there is a next page.
func (*Statement) ExecuteToSingle ¶
Execute the SQL statement against the database and expects a single row, returns the single row or nil if no data is found.