postgres

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package postgres is the Postgres implementation of translation.Store. It uses the skit dbx helpers for query logging and error translation, and stores every translatable column as a row in the translations table keyed by (model_name, column_name, key_id, language_id).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Schema

func Schema() string

Schema returns the DDL for the translations table.

Types

type Store

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

Store implements translation.Store against Postgres.

func NewStore

func NewStore(log *logger.Logger, db *sqlx.DB) *Store

NewStore creates a Postgres-backed Store.

func (*Store) CheckTranslationsExist

func (s *Store) CheckTranslationsExist(ctx context.Context, modelName, keyID string, columns []string, langs []translation.Language) error

CheckTranslationsExist returns ErrMissingTranslations unless every (column, language) pair has a non-empty value.

func (*Store) DeleteTranslations

func (s *Store) DeleteTranslations(ctx context.Context, modelName, keyID string, lang translation.Language) error

DeleteTranslations removes all translations for one model instance and language.

func (*Store) EnsureSchema

func (s *Store) EnsureSchema(ctx context.Context) error

EnsureSchema creates the translations table if absent.

Prefer running the DDL as a migration in production — goose already serializes migrations with its own advisory lock. EnsureSchema is for tests and simple boot-time setup; when several replicas call it concurrently a bare CREATE TABLE IF NOT EXISTS can race, so the DDL runs under a transaction-level advisory lock that auto-releases on commit.

func (*Store) GetTranslations

func (s *Store) GetTranslations(ctx context.Context, modelName, keyID string, lang translation.Language) (map[string]string, error)

GetTranslations returns column_name -> translation_value for one model instance.

func (*Store) GetTranslationsBatch

func (s *Store) GetTranslationsBatch(ctx context.Context, modelName string, keyIDs []string, lang translation.Language) (map[string]map[string]string, error)

GetTranslationsBatch returns keyID -> (column_name -> translation_value) for many instances of the same model in one query.

func (*Store) SaveTranslation

func (s *Store) SaveTranslation(ctx context.Context, data translation.Data) error

SaveTranslation upserts every column of data in a single transaction.

Jump to

Keyboard shortcuts

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