Pillar.BulkInsertBuffer (Pillar v0.30.0) View Source

This module provides functionality for bulk inserts and buffering records

defmodule BulkToLogs do
  use Pillar.BulkInsertBuffer,
    pool: ClickhouseMaster,
    table_name: "logs",
    interval_between_inserts_in_seconds: 5,
    on_errors: &__MODULE__.dump_to_file/2

  def dump_to_file(_result, records) do
    File.write("bad_inserts/2022-06-30 08:50:25.200423Z", inspect(records))
  end
end
:ok = BulkToLogs.insert(%{value: "online", count: 133, datetime: DateTime.utc_now()})
:ok = BulkToLogs.insert(%{value: "online", count: 134, datetime: DateTime.utc_now()})
:ok = BulkToLogs.insert(%{value: "online", count: 132, datetime: DateTime.utc_now()})
....

# all this records will be inserted with 5 second interval