GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — localize_sql/usage-rules.md at main · elixir-localize/localize_sql

Expand file tree

/

usage-rules.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
29 lines (15 loc) · 1.95 KB
/

usage-rules.md

Copy path

File metadata and controls

29 lines (15 loc) · 1.95 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Localize SQL usage rules

Rules for LLM coding agents using localize_sql as a dependency. Not exhaustive — see the HexDocs guides for full reference.

What this package is for

Persisting and querying Localize's data types in a database: Ecto types for them, locale-aware COLLATE for PostgreSQL and SQLite, and PostgreSQL composite types with tag-guarded sum/avg/min/max aggregates for money and units of measure.

Built on localize.

Core conventions

  • Use the provided Ecto types in your schemas rather than storing a formatted string. A formatted value is for a reader in one locale at one moment; the underlying value is what belongs in a column.

  • Unit and money columns are composite types carrying both the magnitude and its tag (the unit or currency). The aggregates are tag-guarded: summing across different units or currencies raises rather than returning a meaningless number.

  • Migrations that create the composite types and aggregate functions live in Localize.Unit.DDL — create_cldr_unit/1, define_aggregate_functions/1 and their drop_* counterparts.

Things not to do

  • Do not sort user-visible text with plain ORDER BY. The database's default collation is not the user's locale, and the result will be wrong for anything outside ASCII. Use the locale-aware COLLATE this package provides.

  • Do not store money as a bare numeric with the currency in a separate column and sum it. Nothing stops the sum crossing currencies. Use the composite type and its guarded aggregate.

  • Do not store a formatted number, date or money string in the database. Store the value; format on the way out, for the reader.

  • Do not assume PostgreSQL. The collation support covers SQLite as well, through the localize_icu loadable extension, with asserted ordering parity between the two.

  • Do not hand-write the composite type DDL. Use Localize.Unit.DDL so the shape matches what the Ecto types expect.

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.