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 ¶
- func Schema() string
- type Store
- func (s *Store) CheckTranslationsExist(ctx context.Context, modelName, keyID string, columns []string, ...) error
- func (s *Store) DeleteTranslations(ctx context.Context, modelName, keyID string, lang translation.Language) error
- func (s *Store) EnsureSchema(ctx context.Context) error
- func (s *Store) GetTranslations(ctx context.Context, modelName, keyID string, lang translation.Language) (map[string]string, error)
- func (s *Store) GetTranslationsBatch(ctx context.Context, modelName string, keyIDs []string, ...) (map[string]map[string]string, error)
- func (s *Store) SaveTranslation(ctx context.Context, data translation.Data) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements translation.Store against Postgres.
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 ¶
EnsureSchema creates the translations table if absent. It is safe to call at startup, including from several replicas at once: the DDL runs under a transaction-scoped advisory lock that auto-releases on commit, so concurrent boots serialize instead of racing on CREATE TABLE.
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 ¶
SaveTranslation upserts every column of data in a single transaction.