model

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package model defines the core ORM entities used throughout the data pipeline.

These structs represent the source tables (e.g., beer, brewery, profile, review), and are used in both ingestion (raw → bronze) and transformation layers (bronze → silver → gold).

Each model is registered dynamically and includes explicit GORM annotations for integration with Aurora PostgreSQL. These models serve as the canonical schema definitions for structured data.

Notes:

  • The `TableName()` method is implemented to enforce schema-qualified naming.
  • Some models (like Review) also include test data generators to support seeding and benchmarking.

This package complements the bronze and dialect layers by enabling schema alignment and data validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(m Model)

Register stores a model implementation in the global registry for later access.

It ensures that each model is registered only once, using the fully qualified table name (e.g., "schema.table") as the key. If a model is nil or has already been registered, the function panics to prevent silent misconfiguration.

Parameters:

  • m: A model implementing the Model interface. Must not be nil and must have a unique TableName.

Usage:

Call this during application startup to make the model available for schema introspection,
dynamic mapping, and downstream processing logic.

Types

type Beer

type Beer struct {
	BeerID    json.Number  `json:"beer_id"    gorm:"column:beer_id;primaryKey"`
	BreweryID json.Number  `json:"brewery_id" gorm:"column:brewery_id"`
	BeerName  string       `json:"beer_name"  gorm:"column:beer_name"`
	BeerStyle string       `json:"beer_style" gorm:"column:beer_style"`
	BeerABV   *json.Number `json:"beer_abv"   gorm:"column:beer_abv"`
}

Beer represents a record from the "beer" table in the raw dataset.

Each field corresponds to a column in the source data and is annotated for both JSON unmarshaling and GORM ORM mapping. The `Beer` struct is typically used for ingestion into the bronze layer of the data lake.

Fields:

  • BeerID: Unique identifier of the beer (primary key).
  • BreweryID: Foreign key referencing the brewery that produced the beer.
  • BeerName: Name of the beer.
  • BeerStyle: Style or category of the beer (e.g., IPA, Lager).
  • BeerABV: Alcohol by volume (ABV) percentage of the beer, optional.

func (Beer) TableName

func (Beer) TableName() string

type Brewery

type Brewery struct {
	BreweryID   json.Number `json:"brewery_id"   gorm:"column:brewery_id;primaryKey"`
	BreweryName string      `json:"brewery_name" gorm:"column:brewery_name"`
}

Brewery represents a record from the "brewery" table in the raw dataset.

This struct is used to map and store brewery metadata, including unique identifiers and names, during the ingestion process into the bronze layer.

Fields:

  • BreweryID: Unique identifier of the brewery (primary key).
  • BreweryName: Name of the brewery.

func (Brewery) TableName

func (Brewery) TableName() string

type Model

type Model interface {
	TableName() string
}

func LoadInstance

func LoadInstance(fullyQualifiedTableName string) (Model, error)

LoadInstance returns a new instance of a registered model.

It first retrieves the model by its fully qualified table name (in the format "schema.table") using LoadModel. Then, it creates a new instance of that model using reflection.

Parameters:

  • fullyQualifiedTableName: The unique identifier of the model in the format "schema.table".

Returns:

  • Model: A new instance of the registered model.
  • error: An error if the model is not found or cannot be instantiated.

func LoadModel

func LoadModel(fullyQualifiedTableName string) (Model, error)

LoadModel retrieves a registered model by its fully qualified table name.

It looks up the model from the global registry using the format "schema.table". If the model is not found, it returns an error indicating that the model has not been registered.

Parameters:

  • fullyQualifiedTableName: The unique identifier for the model in the format "schema.table".

Returns:

  • Model: The registered model instance.
  • error: An error if the model is not found in the registry.

type Profile

type Profile struct {
	ProfileID   json.Number `json:"profile_id"   gorm:"column:profile_id;primaryKey"`
	ProfileName string      `json:"profile_name" gorm:"column:profile_name"`
	Email       string      `json:"email"        gorm:"column:email"`
	State       string      `json:"state"        gorm:"column:state"`
}

Profile represents a user profile record from the "profile" table in the raw dataset.

This struct is used to capture metadata about users who submit reviews, including identifiers, location, and contact information.

Fields:

  • ProfileID: Unique identifier of the user (primary key).
  • ProfileName: Display name of the user.
  • Email: Email address associated with the profile.
  • State: Geographic state or region of the user.

func (Profile) TableName

func (Profile) TableName() string

type Review

type Review struct {
	ReviewID         int64     `json:"review_id"         gorm:"column:review_id;primaryKey"`
	BeerID           int64     `json:"beer_id"           gorm:"column:beer_id"`
	ProfileID        string    `json:"profile_id"        gorm:"column:profile_id"`
	ReviewOverall    float64   `json:"review_overall"    gorm:"column:review_overall"`
	ReviewAroma      float64   `json:"review_aroma"      gorm:"column:review_aroma"`
	ReviewAppearance float64   `json:"review_appearance" gorm:"column:review_appearance"`
	ReviewPalate     float64   `json:"review_palate"     gorm:"column:review_palate"`
	ReviewTaste      float64   `json:"review_taste"      gorm:"column:review_taste"`
	ReviewTime       time.Time `json:"review_time"       gorm:"column:review_time"`
}

Review represents a user-submitted review of a beer in the raw dataset.

This struct captures both the subjective evaluation and metadata related to when and by whom the review was submitted.

Fields:

  • ReviewID: Unique identifier for the review (primary key).
  • BeerID: Foreign key referencing the reviewed beer.
  • ProfileID: Identifier of the user who submitted the review.
  • ReviewOverall: Overall rating given to the beer.
  • ReviewAroma: Rating for the aroma of the beer.
  • ReviewAppearance: Rating for the appearance of the beer.
  • ReviewPalate: Rating for the palate/mouthfeel of the beer.
  • ReviewTaste: Rating for the taste of the beer.
  • ReviewTime: Timestamp indicating when the review was created.

func (Review) TableName

func (Review) TableName() string

Jump to

Keyboard shortcuts

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