schema

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package schema provides event schema parsing and code generation.

It reads YAML schema definitions and generates:

  • SQL DDL for PostgreSQL tables
  • Go models with validation tags
  • Storage layer code using pgx COPY protocol

The schema-first approach ensures consistency between database, application code, and validation rules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateConsumer

func GenerateConsumer(schema *Schema) (string, error)

GenerateConsumer generates consumer event routing and batch handling code

func GenerateGo

func GenerateGo(schema *Schema) (string, error)

GenerateGo generates Go structs for all events in the schema

func GenerateSDK

func GenerateSDK(schema *Schema, language SDKLanguage, apiURL string) (map[string]string, error)

GenerateSDK generates SDK code for the specified language

func GenerateSQL

func GenerateSQL(schema *Schema) (string, error)

GenerateSQL generates PostgreSQL DDL for all events in the schema

func GenerateStorage

func GenerateStorage(schema *Schema) (string, error)

GenerateStorage generates PostgreSQL storage writer code for all events

Types

type Event

type Event struct {
	Description string            `yaml:"description"`
	Fields      map[string]*Field `yaml:"fields"`
}

Event represents a single event type definition

func (*Event) Validate

func (e *Event) Validate(eventName string) error

Validate performs validation on an event

type Field

type Field struct {
	Type        string   `yaml:"type"`
	Required    bool     `yaml:"required"`
	Indexed     bool     `yaml:"indexed"`
	Description string   `yaml:"description"`
	Default     string   `yaml:"default"`
	Values      []string `yaml:"values"`
}

Field represents a field in an event

func (*Field) Validate

func (f *Field) Validate(eventName, fieldName string) error

Validate performs validation on a field

type SDKLanguage

type SDKLanguage string

SDKLanguage represents a target SDK language

const (
	SDKLanguagePython     SDKLanguage = "python"
	SDKLanguageTypeScript SDKLanguage = "typescript"
	SDKLanguageGo         SDKLanguage = "go"
	SDKLanguageJava       SDKLanguage = "java"
)

type Schema

type Schema struct {
	Version string            `yaml:"version"`
	Events  map[string]*Event `yaml:"events"`
}

Schema represents the entire event schema definition

func ParseSchema

func ParseSchema(data []byte) (*Schema, error)

ParseSchema parses YAML schema data. The schema is automatically validated during parsing, so callers do not need to call Validate() separately. Returns a validated Schema or an error if parsing or validation fails.

func ParseSchemaFile

func ParseSchemaFile(path string) (*Schema, error)

ParseSchemaFile reads and parses a YAML schema file. The schema is automatically validated during parsing, so callers do not need to call Validate() separately.

func (*Schema) GetEventNames

func (s *Schema) GetEventNames() []string

GetEventNames returns a sorted list of event names

func (*Schema) Validate

func (s *Schema) Validate() error

Validate performs validation on the schema

Jump to

Keyboard shortcuts

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