Adapter for using Calendar library types (Date, Time, DateTime) with Ecto schemas in Elixir.
Calecto is an adapter library for Elixir that integrates the Calendar library with Ecto, allowing developers to use Calendar's date, time, and datetime types directly in Ecto schemas. It solves the problem of handling timezone-aware datetimes and provides rich formatting and parsing capabilities for database-stored timestamps.
Elixir developers using Ecto for database interactions who need advanced date/time handling, especially those working with timezone-aware data or requiring formatting beyond basic Ecto types.
Developers choose Calecto for its seamless integration of Calendar's powerful datetime features into Ecto, offering timezone support, flexible formatting, and compatibility with both modern and legacy Ecto versions.
Adapter for the Calendar library in Ecto
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Enables storing any Calendar.DateTime struct with full timezone data in Postgres via the Calecto.DateTime type, allowing accurate wall-time representation across timezones, as highlighted in the README's Postgres-specific section.
Integrates Calendar's formatting functions like strftime, Unix timestamps, and RFC 3339 directly on Ecto timestamps, simplifying display and manipulation without extra conversions, as shown in the formatting examples.
Provides backwards compatibility for Ecto versions prior to 2.1, allowing older applications to use Calendar types without upgrading Ecto, which is explicitly stated in the README's versioning notes.
With a single `use Calecto.Schema` line in models or Phoenix's web.ex, timestamps and fields are automatically upgraded to use Calendar types, reducing boilerplate code for quick adoption.
The key feature of timezone-aware datetimes (Calecto.DateTime) is exclusive to Postgres, making it unsuitable for MySQL or SQLite users needing similar functionality, as admitted in the README.
For Ecto 2.1 and newer, most Calecto types are redundant as Ecto has built-in equivalents, adding unnecessary dependency unless specific Postgres timezone support is needed, per the README's caution.
Using Calecto.DateTime with Postgres requires running a custom migration (`mix calecto.add_type_migration`) to add the calendar_datetime type, adding setup complexity compared to native Ecto types.