write

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package write contains a package-authored Datly 1.0 writer example.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordInputRequired = errors.New("record patch input is required")
	ErrRecordUnauthorized  = errors.New("record patch is not authorized")
)

Functions

func NewRecordPatchHandler

func NewRecordPatchHandler() xhandler.Contract[RecordInput, RecordOutput]

NewRecordPatchHandler is the zero-argument authored factory retained by component metadata and transcription. Runtime assembly injects fixed primitives through NewRecordPatchRuntimeHandler.

func NewRecordPatchRuntimeHandler

func NewRecordPatchRuntimeHandler(capabilities xhandler.Capabilities) rhandler.TypedHandler

NewRecordPatchRuntimeHandler is the fixed runtime injection seam for the named component handler. Generated/bootstrap registration assigns its result to registry.RegisteredComponent.Handler.

Types

type AuthOutput

type AuthOutput struct {
	Allowed bool `parameter:"Allowed,kind=output,in=allowed"`
}

type Components

type Components struct {
	RecordPatch xdatly.Component[RecordInput, RecordOutput] `` /* 157-byte string literal not displayed */
}

Components is the Datly 1.0 package-level component declaration. The named handler owns record validation and DML orchestration.

type IDSet

type IDSet struct {
	Values []int
}

type Record

type Record struct {
	ID               int        `json:"id,omitempty" sqlx:"ID,primaryKey=true,autoincrement=true"`
	ParentID         *int       `json:"parentId,omitempty" sqlx:"PARENT_ID"`
	Name             string     `json:"name,omitempty" sqlx:"NAME"`
	Target           *string    `json:"target,omitempty" sqlx:"TARGET"`
	Exclusion        *string    `json:"exclusion,omitempty" sqlx:"EXCLUSION"`
	UnitPrice        *float64   `json:"unitPrice,omitempty" sqlx:"UNIT_PRICE"`
	Weight           int        `json:"weight,omitempty" sqlx:"WEIGHT"`
	Status           int        `json:"status,omitempty" sqlx:"STATUS"`
	RateLimit        *float64   `json:"rateLimit,omitempty" sqlx:"RATE_LIMIT"`
	RateDuration     *int       `json:"rateDuration,omitempty" sqlx:"RATE_DURATION"`
	RateWindow       *int       `json:"rateWindow,omitempty" sqlx:"RATE_WINDOW"`
	LifetimeLimit    float64    `json:"lifetimeLimit,omitempty" sqlx:"LIFETIME_LIMIT"`
	ExternalRecordID *string    `json:"externalRecordId,omitempty" sqlx:"EXTERNAL_RECORD_ID"`
	CapacityLimit    *int       `json:"capacityLimit,omitempty" sqlx:"CAPACITY_LIMIT"`
	ManualAssignment int        `json:"manualAssignment,omitempty" sqlx:"MANUAL_ASSIGNMENT"`
	IsPriority       int        `json:"isPriority,omitempty" sqlx:"IS_PRIORITY"`
	Created          *time.Time `json:"-" sqlx:"CREATED"`
	CreatedUser      *int       `json:"-" sqlx:"CREATED_USER"`
	Updated          *time.Time `json:"-" sqlx:"UPDATED"`
	UpdatedUser      *int       `json:"-" sqlx:"UPDATED_USER"`

	Has *RecordHas `json:"-" sqlx:"-" setMarker:"true" typeName:"RecordHas"`
}

Record is the writable RECORDS record.

type RecordHas

type RecordHas struct {
	ID               bool
	ParentID         bool
	Name             bool
	Target           bool
	Exclusion        bool
	UnitPrice        bool
	Weight           bool
	Status           bool
	RateLimit        bool
	RateDuration     bool
	RateWindow       bool
	LifetimeLimit    bool
	ExternalRecordID bool
	CapacityLimit    bool
	ManualAssignment bool
	IsPriority       bool
	Created          bool
	CreatedUser      bool
	Updated          bool
	UpdatedUser      bool
}

RecordHas distinguishes an absent PATCH property from an explicit zero or null value.

type RecordInput

type RecordInput struct {
	JWT *jwt.Claims `parameter:"JWT,kind=header,in=Authorization,dataType=string,errorCode=401" codec:"JwtClaim"`

	Auth *AuthOutput `parameter:"Auth,kind=component,in=GET:/v1/api/platform/acl/auth,required"`

	Method      string    `parameter:"Method,kind=http_request,in=method"`
	RequestTime time.Time `parameter:"RequestTime,kind=generator,in=current_time"`
	Source      string    `parameter:"Source,kind=query,in=source"`

	Records []*Record `parameter:"Records,kind=body,in=data,cardinality=Many,required"`

	RecordIDs *IDSet `parameter:"RecordIDs,kind=param,in=Records" codec:"structql,uri=record/cur_record_ids.sql"`

	CurrentRecords []*Record `` /* 514-byte string literal not displayed */
}

RecordInput demonstrates the complete writer binding chain: request metadata, a child component, request body, derived parameters, and current database state.

type RecordOutput

type RecordOutput struct {
	Status string `json:"status" parameter:"Status,kind=output,in=status"`

	Data []*Record `` /* 130-byte string literal not displayed */

	Violations []string `json:"violations,omitempty" parameter:"Violations,kind=output,in=violations"`
}

type RecordPatchHandler

type RecordPatchHandler struct {
	Logger    xhandler.Logger
	Validator xhandler.Validator
	// MessageBus is fixed-injected for post-commit coordination only. Exec does
	// not publish before the root transaction commits.
	MessageBus xhandler.MessageBus
}

RecordPatchHandler owns RECORDS write orchestration. Stable handler services are construction-injected fields. Request/transaction-scoped Data remains invocation-injected through the session binder.

func (*RecordPatchHandler) Exec

func (h *RecordPatchHandler) Exec(ctx context.Context, session xhandler.Session, input *RecordInput, output *RecordOutput) error

Jump to

Keyboard shortcuts

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