Documentation ¶
Index ¶
- Constants
- 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 CreateExternalIdentity(ctx context.Context, schema *proto.Schema, externalId string, issuer string, ...) (*runtimectx.Identity, error)
- func CreateIdentity(ctx context.Context, schema *proto.Schema, email string, password string) (*runtimectx.Identity, error)
- func Delete(scope *Scope, input map[string]any) (*string, error)
- func Execute(scope *Scope, inputs any) (result any, headers map[string][]string, err error)
- func FindIdentityByEmail(ctx context.Context, schema *proto.Schema, email string) (*runtimectx.Identity, error)
- func FindIdentityByExternalId(ctx context.Context, schema *proto.Schema, externalId string, issuer string) (*runtimectx.Identity, error)
- func FindIdentityById(ctx context.Context, schema *proto.Schema, id string) (*runtimectx.Identity, error)
- func GenerateBearerToken(ctx context.Context, identityId string) (string, error)
- func GenerateListStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, *Page, error)
- func GenerateResetToken(ctx context.Context, identityId string) (string, error)
- func Get(scope *Scope, input map[string]any) (map[string]any, error)
- func HandleAuthorizationHeader(ctx context.Context, schema *proto.Schema, headers http.Header) (*runtimectx.Identity, error)
- func HandleBearerToken(ctx context.Context, schema *proto.Schema, token string) (*runtimectx.Identity, error)
- func List(scope *Scope, input map[string]any) (map[string]any, error)
- func ResetPassword(scope *Scope, input map[string]any) error
- 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 ValidateBearerToken(ctx context.Context, tokenString string) (string, string, error)
- func ValidateResetToken(ctx context.Context, tokenString string) (string, error)
- type ActionOperator
- type AuthenticateResult
- type Claims
- type ExternalUserDetails
- type JoinOption
- type JoinType
- type Page
- type PageInfo
- type QueryBuilder
- func (query *QueryBuilder) AddWriteValue(fieldName string, value any)
- func (query *QueryBuilder) AddWriteValues(values map[string]any)
- 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() *Statement
- func (query *QueryBuilder) InsertStatement() *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() *Statement
- func (query *QueryBuilder) Where(left *QueryOperand, operator ActionOperator, right *QueryOperand) error
- type QueryBuilderOption
- type 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 ¶
Variables ¶
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 CreateExternalIdentity ¶
func CreateIdentity ¶
func FindIdentityByEmail ¶
func FindIdentityById ¶
func GenerateBearerToken ¶
func GenerateListStatement ¶
func GenerateResetToken ¶
func HandleBearerToken ¶
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.
func ValidateBearerToken ¶
Verifies the bearer token and returns the JWT subject and issuer.
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 AuthenticateResult ¶
type AuthenticateResult struct { Token string `json:"token"` IdentityCreated bool `json:"identityCreated"` }
func Authenticate ¶
func Authenticate(scope *Scope, input map[string]any) (*AuthenticateResult, error)
Authenticate will return the identity ID if it is successfully authenticated or when a new identity is created.
type Claims ¶
type Claims struct {
jwt.RegisteredClaims
}
https://pkg.go.dev/github.com/golang-jwt/jwt/v4#RegisteredClaims
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.
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(fieldName string, value any)
Includes a value to be written during an INSERT or UPDATE.
func (*QueryBuilder) AddWriteValues ¶
func (query *QueryBuilder) AddWriteValues(values map[string]any)
Includes root values to be written during an INSERT or UPDATE for a model.
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() *Statement
Generates an executable DELETE statement with the list of arguments.
func (*QueryBuilder) InsertStatement ¶
func (query *QueryBuilder) InsertStatement() *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() *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 (*QueryOperand) IsField ¶
func (o *QueryOperand) IsField() bool
func (*QueryOperand) IsInlineQuery ¶
func (o *QueryOperand) IsInlineQuery() bool
func (*QueryOperand) IsNull ¶
func (o *QueryOperand) IsNull() bool
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.