enumdb

package
v1.80.9 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package enumdb provides simple methods to store and retrieve enumerations from database tables. Each enumeration has a numerical ID ("id" on the database table as primary key) and a string name ("name" database table as unique string). Example of table:

CREATE TABLE IF NOT EXISTS `example` (
  `id` SMALLINT UNSIGNED NOT NULL,
  `name` VARCHAR(50) NOT NULL,
  `disabled` TINYINT NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `id_UNIQUE` (`id` ASC),
  UNIQUE INDEX `name_UNIQUE` (`name` ASC))
ENGINE = InnoDB
COMMENT = 'Example enumeration table';

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnumDB

type EnumDB map[string]*enumcache.EnumCache

EnumDB maps each enumeration table name with the corresponding enumeration cache.

func New

func New(ctx context.Context, db *sql.DB, queries EnumTableQuery) (EnumDB, error)

New returns a new enumeration cache for all the tables listed in the queries map.

type EnumTableQuery

type EnumTableQuery map[string]string

EnumTableQuery maps each enumeration table name with the SQL query string used to read the data.

Jump to

Keyboard shortcuts

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