AshClickhouse.DataLayer.Insert (AshClickhouse v0.6.2)

Copy Markdown View Source

Builds the values and SQL fragments used to insert/update rows.

Extracted from AshClickhouse.DataLayer so all persistence value encoding (attribute ordering, UUID/decimal/date/time handling, autogenerated primary keys) lives in one module and can be reused by the single- and bulk-insert paths.

Summary

Functions

Encodes a single record's attrs into a row map (string keys → encoded values) suitable for the single-insert path.

Builds a (fields, rows) pair for bulk insert: quoted column names in the resource's attribute declaration order, and each row as a value list aligned to that order.

Builds column = ? SET clauses and their values (for ALTER TABLE ... UPDATE).

Builds an AND-joined col = ? WHERE clause and its values from a pk map.

Returns a changeset's attributes map with autogenerated values filled in for missing primary keys.

Merges attributes and changes from a changeset into a single map for the SET clause builder.

Encodes a single attribute value for a parameterized query.

Builds a map of primary-key column → value from a changeset's current data.

Builds the options forwarded to a bulk insert (async_insert etc.).

Builds a fully-formed INSERT INTO <table> (...) FORMAT JSONCompactEachRow statement from already-built fields.

Functions

attrs_to_row(attrs, resource)

@spec attrs_to_row(map(), module()) :: map()

Encodes a single record's attrs into a row map (string keys → encoded values) suitable for the single-insert path.

build_insert_rows(rows, resource)

@spec build_insert_rows([map()], module()) :: {[String.t()], [list()]}

Builds a (fields, rows) pair for bulk insert: quoted column names in the resource's attribute declaration order, and each row as a value list aligned to that order.

build_set_clauses(attrs, resource)

@spec build_set_clauses(map(), module()) :: {[String.t()], [term()]}

Builds column = ? SET clauses and their values (for ALTER TABLE ... UPDATE).

build_where_from_map(pk_map, resource)

@spec build_where_from_map(map(), module()) :: {String.t(), [term()]}

Builds an AND-joined col = ? WHERE clause and its values from a pk map.

changeset_to_insert_attrs(changeset, resource)

@spec changeset_to_insert_attrs(map(), module()) :: map()

Returns a changeset's attributes map with autogenerated values filled in for missing primary keys.

changeset_to_update_attrs(changeset, resource)

@spec changeset_to_update_attrs(map(), term()) :: map()

Merges attributes and changes from a changeset into a single map for the SET clause builder.

encode_attr_value(key, value, attr_map, uuid_fields)

@spec encode_attr_value(atom(), term(), map(), MapSet.t()) :: term()

Encodes a single attribute value for a parameterized query.

get_primary_key_from_changeset(changeset, resource)

@spec get_primary_key_from_changeset(map(), module()) :: map()

Builds a map of primary-key column → value from a changeset's current data.

insert_opts(resource, opts)

@spec insert_opts(
  module(),
  keyword()
) :: keyword()

Builds the options forwarded to a bulk insert (async_insert etc.).

insert_statement(qualified, fields)

@spec insert_statement(String.t(), [String.t()]) :: String.t()

Builds a fully-formed INSERT INTO <table> (...) FORMAT JSONCompactEachRow statement from already-built fields.