Ecto.Adapters.LibSql.Connection (EctoLibSql v0.8.8)

Copy Markdown View Source

Implementation of Ecto.Adapters.SQL.Connection for LibSQL.

This module handles SQL query generation and DDL operations for LibSQL/SQLite. It implements the Ecto.Adapters.SQL.Connection behaviour, translating Ecto's query structures into SQLite-compatible SQL.

Key Responsibilities

  • Query generation (all/1, update_all/1, delete_all/1)
  • Insert/update/delete operations with RETURNING support
  • DDL generation (CREATE TABLE, ALTER TABLE, CREATE INDEX, etc.)
  • Constraint name extraction for error handling
  • Type mapping between Ecto and SQLite

SQLite Compatibility

This module ensures generated SQL is compatible with SQLite/LibSQL syntax, including handling of AUTOINCREMENT, ON CONFLICT clauses, and type affinities.

Summary

Functions

Parse a SQLite error message and map it to a list of Ecto constraint tuples.

Functions

to_constraints(map, opts)

@spec to_constraints(%{message: String.t()}, Keyword.t()) :: Keyword.t()

Parse a SQLite error message and map it to a list of Ecto constraint tuples.

Accepts an exception-like map containing a SQLite error :message and returns recognised constraint information such as unique, foreign_key or check constraints; returns an empty list when no known constraint pattern is found.

Parameters

  • error: Map containing a :message string produced by SQLite.
  • _opts: Options (unused).

Returns

  • A keyword list of constraint tuples, for example [unique: "table_column_index"], [foreign_key: :unknown], [check: "constraint_name"], or [] when no constraint is recognised.