database

package
v0.0.0-...-52f9fe0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package database manages MySQL database connection and access functions.

Index

Constants

This section is empty.

Variables

View Source
var DB *sql.DB

DB is the global database connection used across the application. It should be initialized via InitDatabase before use.

Functions

func BuildLanguageStatResponse

func BuildLanguageStatResponse(code string, stat map[string]any) models.LanguageStatisticsReponse

BuildLanguageStatResponse constructs a LanguageStatisticsResponse object from raw stat data.

func CreateLanguageDataVersionsTable

func CreateLanguageDataVersionsTable() error

CreateLanguageDataVersionsTable creates the `language_data_versions` table if it does not already exist. This table tracks the last updated time for each language's dataset.

func GetAllLanguageStats

func GetAllLanguageStats() ([]models.LanguageStatisticsReponse, error)

GetAllLanguageStats retrieves statistics for all available languages (only nouns and verbs).

func GetAvailableLanguages

func GetAvailableLanguages() ([]string, error)

GetAvailableLanguages retrieves all available languages in the database.

func GetLanguageDataTypes

func GetLanguageDataTypes(lang string) ([]string, error)

GetLanguageDataTypes retrieves all available data types in a sample language table.

func GetLanguageDisplayName

func GetLanguageDisplayName(code string) string

GetLanguageDisplayName returns the display name for a given language code.

func GetLanguageStat

func GetLanguageStat(lan string) (map[string]any, error)

GetLanguageStat retrieves noun and verb statistics for a specific language.

func GetLanguageVersions

func GetLanguageVersions(lang string) (map[string]string, error)

GetLanguageVersions returns a map of data types to their last modified date for the given language.

func GetTableData

func GetTableData(tableName string) ([]map[string]any, error)

GetTableData retrieves all rows and columns from a given table. The result is a slice of maps, where each map represents a row with column-value pairs.

func GetTableSchema

func GetTableSchema(tableName string) (map[string]string, error)

GetTableSchema returns the column names and types for a specific table in the connected MySQL/MariaDB database.

func InitDatabase

func InitDatabase() error

InitDatabase initializes the database connection.

func IsValidTableName

func IsValidTableName(tableName string) bool

IsValidTableName validates table names to prevent SQL injection.

func TableExists

func TableExists(tableName string) (bool, error)

TableExists checks if a table exists in the database.

func ToIntPtr

func ToIntPtr(v any) *int

ToIntPtr converts various numeric types to a pointer to int.

func ToStringPtr

func ToStringPtr(v any) *string

ToStringPtr converts a string to a pointer to string.

func UpdateLanguageVersion

func UpdateLanguageVersion(lang string) error

UpdateLanguageVersion updates the `updated_at` timestamp for a specific language in the `language_data_versions` table. If the language does not exist, it inserts a new row.

Types

This section is empty.

Jump to

Keyboard shortcuts

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