{"modulePath":"github.com/viant/datly","version":"v1.1.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package write\n\nPackage write contains a package-authored Datly 1.0 writer example.\n\n## Variables\n\n```go\nvar (\n\tErrRecordInputRequired = errors.New(\"record patch input is required\")\n\tErrRecordUnauthorized  = errors.New(\"record patch is not authorized\")\n)\n```\n\n## Functions\n\n```go\nfunc NewRecordPatchHandler() xhandler.Contract[RecordInput, RecordOutput]\n```\nNewRecordPatchHandler is the zero-argument authored factory retained by component metadata and transcription. Runtime assembly injects fixed primitives through NewRecordPatchRuntimeHandler.\n\n```go\nfunc NewRecordPatchRuntimeHandler(capabilities xhandler.Capabilities) rhandler.TypedHandler\n```\nNewRecordPatchRuntimeHandler is the fixed runtime injection seam for the named component handler. Generated/bootstrap registration assigns its result to registry.RegisteredComponent.Handler.\n\n## Types\n\n```go\ntype AuthOutput struct {\n\tAllowed bool `parameter:\"Allowed,kind=output,in=allowed\"`\n}\n```\n\n```go\ntype Components struct {\n\tRecordPatch xdatly.Component[RecordInput, RecordOutput] `component:\"RecordPatch,path=/v1/api/records,method=PATCH,connector=main,handler=NewRecordPatchHandler,view=Record\" desc:\"Inserts and updates RECORDS records\"`\n}\n```\nComponents is the Datly 1.0 package-level component declaration. The named handler owns record validation and DML orchestration.\n\n```go\ntype IDSet struct {\n\tValues []int\n}\n```\n\n```go\ntype Record struct {\n\tID               int        `json:\"id,omitempty\" sqlx:\"ID,primaryKey=true,autoincrement=true\"`\n\tParentID         *int       `json:\"parentId,omitempty\" sqlx:\"PARENT_ID\"`\n\tName             string     `json:\"name,omitempty\" sqlx:\"NAME\"`\n\tTarget           *string    `json:\"target,omitempty\" sqlx:\"TARGET\"`\n\tExclusion        *string    `json:\"exclusion,omitempty\" sqlx:\"EXCLUSION\"`\n\tUnitPrice        *float64   `json:\"unitPrice,omitempty\" sqlx:\"UNIT_PRICE\"`\n\tWeight           int        `json:\"weight,omitempty\" sqlx:\"WEIGHT\"`\n\tStatus           int        `json:\"status,omitempty\" sqlx:\"STATUS\"`\n\tRateLimit        *float64   `json:\"rateLimit,omitempty\" sqlx:\"RATE_LIMIT\"`\n\tRateDuration     *int       `json:\"rateDuration,omitempty\" sqlx:\"RATE_DURATION\"`\n\tRateWindow       *int       `json:\"rateWindow,omitempty\" sqlx:\"RATE_WINDOW\"`\n\tLifetimeLimit    float64    `json:\"lifetimeLimit,omitempty\" sqlx:\"LIFETIME_LIMIT\"`\n\tExternalRecordID *string    `json:\"externalRecordId,omitempty\" sqlx:\"EXTERNAL_RECORD_ID\"`\n\tCapacityLimit    *int       `json:\"capacityLimit,omitempty\" sqlx:\"CAPACITY_LIMIT\"`\n\tManualAssignment int        `json:\"manualAssignment,omitempty\" sqlx:\"MANUAL_ASSIGNMENT\"`\n\tIsPriority       int        `json:\"isPriority,omitempty\" sqlx:\"IS_PRIORITY\"`\n\tCreated          *time.Time `json:\"-\" sqlx:\"CREATED\"`\n\tCreatedUser      *int       `json:\"-\" sqlx:\"CREATED_USER\"`\n\tUpdated          *time.Time `json:\"-\" sqlx:\"UPDATED\"`\n\tUpdatedUser      *int       `json:\"-\" sqlx:\"UPDATED_USER\"`\n\n\tHas *RecordHas `json:\"-\" sqlx:\"-\" setMarker:\"true\" typeName:\"RecordHas\"`\n}\n```\nRecord is the writable RECORDS record.\n\n```go\ntype RecordHas struct {\n\tID               bool\n\tParentID         bool\n\tName             bool\n\tTarget           bool\n\tExclusion        bool\n\tUnitPrice        bool\n\tWeight           bool\n\tStatus           bool\n\tRateLimit        bool\n\tRateDuration     bool\n\tRateWindow       bool\n\tLifetimeLimit    bool\n\tExternalRecordID bool\n\tCapacityLimit    bool\n\tManualAssignment bool\n\tIsPriority       bool\n\tCreated          bool\n\tCreatedUser      bool\n\tUpdated          bool\n\tUpdatedUser      bool\n}\n```\nRecordHas distinguishes an absent PATCH property from an explicit zero or null value.\n\n```go\ntype RecordInput struct {\n\tJWT *jwt.Claims `parameter:\"JWT,kind=header,in=Authorization,dataType=string,errorCode=401\" codec:\"JwtClaim\"`\n\n\tAuth *AuthOutput `parameter:\"Auth,kind=component,in=GET:/v1/api/platform/acl/auth,required\"`\n\n\tMethod      string    `parameter:\"Method,kind=http_request,in=method\"`\n\tRequestTime time.Time `parameter:\"RequestTime,kind=generator,in=current_time\"`\n\tSource      string    `parameter:\"Source,kind=query,in=source\"`\n\n\tRecords []*Record `parameter:\"Records,kind=body,in=data,cardinality=Many,required\"`\n\n\tRecordIDs *IDSet `parameter:\"RecordIDs,kind=param,in=Records\" codec:\"structql,uri=record/cur_record_ids.sql\"`\n\n\tCurrentRecords []*Record `parameter:\"CurrentRecords,kind=view,in=CurrentRecords,cardinality=Many\" view:\"CurrentRecords,type=Record,table=RECORDS,connector=main,limit=0\" sql:\"SELECT au.ID, au.PARENT_ID, au.NAME, au.TARGET, au.EXCLUSION, au.UNIT_PRICE, au.WEIGHT, au.STATUS, au.RATE_LIMIT, au.RATE_DURATION, au.RATE_WINDOW, au.LIFETIME_LIMIT, au.EXTERNAL_RECORD_ID, au.CAPACITY_LIMIT, au.MANUAL_ASSIGNMENT, au.IS_PRIORITY, au.CREATED, au.CREATED_USER, au.UPDATED, au.UPDATED_USER FROM RECORDS au WHERE $criteria.In(\\\"ID\\\", $RecordIDs.Values)\"`\n}\n```\nRecordInput demonstrates the complete writer binding chain: request metadata, a child component, request body, derived parameters, and current database state.\n\n```go\ntype RecordOutput struct {\n\tStatus string `json:\"status\" parameter:\"Status,kind=output,in=status\"`\n\n\tData []*Record `json:\"data,omitempty\" parameter:\"Data,kind=output,in=view,cardinality=Many\" view:\"Record,type=Record,table=RECORDS,connector=main\"`\n\n\tViolations []string `json:\"violations,omitempty\" parameter:\"Violations,kind=output,in=violations\"`\n}\n```\n\n```go\ntype RecordPatchHandler struct {\n\tLogger    xhandler.Logger\n\tValidator xhandler.Validator\n\t// MessageBus is fixed-injected for post-commit coordination only. Exec does\n\t// not publish before the root transaction commits.\n\tMessageBus xhandler.MessageBus\n}\n```\nRecordPatchHandler owns RECORDS write orchestration. Stable handler services are construction-injected fields. Request/transaction-scoped Data remains invocation-injected through the session binder.\n\n```go\nfunc (h *RecordPatchHandler) Exec(ctx context.Context, session xhandler.Session, input *RecordInput, output *RecordOutput) error\n```\n\n","path":"github.com/viant/datly/example/write","name":"write","synopsis":"Package write contains a package-authored Datly 1.0 writer example.","isRedistributable":true}
