database

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(ctx context.Context, log *zap.Logger, cfg *config.Config) (*Database, error)

func (*Database) BeginTransaction

func (d *Database) BeginTransaction() *gorm.DB

func (*Database) CreateComponent

func (d *Database) CreateComponent(dashboard *models.Dashboard, name string, cType models.ComponentType, configs interface{}, query string) (*models.Component, error)

func (*Database) CreateDashboard

func (d *Database) CreateDashboard(name string) (*models.Dashboard, error)

func (*Database) DeleteComponent

func (d *Database) DeleteComponent(component *models.Component) error

func (*Database) DeleteDashboard

func (d *Database) DeleteDashboard(dashboard *models.Dashboard) error

func (*Database) GetActivity

func (d *Database) GetActivity(id string) (*models.Activity, error)

func (*Database) GetAthlete

func (d *Database) GetAthlete(id string) (*models.Athlete, error)

func (*Database) GetComponent

func (d *Database) GetComponent(dashboardID, componentID uint) (*models.Component, error)

func (*Database) GetConnection

func (d *Database) GetConnection() *gorm.DB

func (*Database) GetCurrentConfig

func (d *Database) GetCurrentConfig() (*models.Config, error)

func (*Database) GetDashboard

func (d *Database) GetDashboard(dashboardID uint) (*models.Dashboard, error)

func (*Database) GetGear

func (d *Database) GetGear(id string) (*models.Gear, error)

func (*Database) GetLatestActivity

func (d *Database) GetLatestActivity() (*models.Activity, error)

func (*Database) GetModelsSchema added in v0.3.0

func (d *Database) GetModelsSchema() ([]Schema, error)

GetModelsSchema retrieves the schema information of the database models. It parses the fields of predefined models (Activity, Athlete, Gear) and returns their schema details.

func (*Database) ListActivities

func (d *Database) ListActivities(offset, limit int) (int64, []models.Activity, error)

func (*Database) ListAthletes

func (d *Database) ListAthletes(offset, limit int) (int64, []models.Athlete, error)

func (*Database) ListComponents

func (d *Database) ListComponents(dashboardId uint) ([]models.Component, error)

func (*Database) ListDashboards

func (d *Database) ListDashboards(offset, limit int) (int64, []models.Dashboard, error)

func (*Database) ListGears

func (d *Database) ListGears(offset, limit int) (int64, []models.Gear, error)

func (*Database) Migrate

func (d *Database) Migrate() error

func (*Database) RunQuery

func (d *Database) RunQuery(query string) ([]map[string]interface{}, error)

RunQuery runs a SQL query after compiling it with date placeholders. It executes the query and returns the results as a slice of maps, where each map represents a row with column names as keys and column values as values. Parameters: - query: The SQL query template containing placeholders.

func (*Database) UpdateComponent

func (d *Database) UpdateComponent(component *models.Component) error

func (*Database) UpdateDashboard

func (d *Database) UpdateDashboard(dashboard *models.Dashboard) error

func (*Database) UpsertActivities

func (d *Database) UpsertActivities(tx *gorm.DB, activities []models.Activity) error

func (*Database) UpsertAthlete

func (d *Database) UpsertAthlete(tx *gorm.DB, athlete *models.Athlete) error

func (*Database) UpsertConfig

func (d *Database) UpsertConfig(in models.Config) (*models.Config, error)

func (*Database) UpsertGears

func (d *Database) UpsertGears(tx *gorm.DB, gears []models.Gear) error

type Schema added in v0.3.0

type Schema struct {
	TableName string `json:"table_name"`
	DBName    string `json:"field_db_name"`
	Type      string `json:"type"`
}

Schema represents the schema information of a database field.

Jump to

Keyboard shortcuts

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