Documentation
¶
Overview ¶
Package database manages MySQL database connection and access functions.
Index ¶
- Variables
- func BuildLanguageStatResponse(code string, stat map[string]any) models.LanguageStatisticsReponse
- func CreateLanguageDataVersionsTable() error
- func GetAllLanguageStats() ([]models.LanguageStatisticsReponse, error)
- func GetAvailableLanguages() ([]string, error)
- func GetLanguageDataTypes(lang string) ([]string, error)
- func GetLanguageDisplayName(code string) string
- func GetLanguageStat(lan string) (map[string]any, error)
- func GetLanguageVersions(lang string) (map[string]string, error)
- func GetTableData(tableName string) ([]map[string]any, error)
- func GetTableSchema(tableName string) (map[string]string, error)
- func InitDatabase() error
- func IsValidTableName(tableName string) bool
- func TableExists(tableName string) (bool, error)
- func ToIntPtr(v any) *int
- func ToStringPtr(v any) *string
- func UpdateLanguageVersion(lang string) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
GetAvailableLanguages retrieves all available languages in the database.
func GetLanguageDataTypes ¶
GetLanguageDataTypes retrieves all available data types in a sample language table.
func GetLanguageDisplayName ¶
GetLanguageDisplayName returns the display name for a given language code.
func GetLanguageStat ¶
GetLanguageStat retrieves noun and verb statistics for a specific language.
func GetLanguageVersions ¶
GetLanguageVersions returns a map of data types to their last modified date for the given language.
func GetTableData ¶
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 ¶
GetTableSchema returns the column names and types for a specific table in the connected MySQL/MariaDB database.
func IsValidTableName ¶
IsValidTableName validates table names to prevent SQL injection.
func TableExists ¶
TableExists checks if a table exists in the database.
func ToStringPtr ¶
ToStringPtr converts a string to a pointer to string.
func UpdateLanguageVersion ¶
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.