Module kflow_postgres

This module inserts a batch of Erlang maps as rows in a Postgres table.

Copyright © 2018-2020 Klarna Bank AB (publ)

Description

This module inserts a batch of Erlang maps as rows in a Postgres table.

Input message format

   [ #{field1 => val1, field2 => val2}
   , #{field1 => val3, field2 => val4}
   ]

Output message format

Input message is returned as is.

Configuration

Configuration is a term of config/0 type. It's a map with the following mandatory fields:

The following options are optional:

Automated partitioning

This module can create table partitions automatically when partitioning` key is present in the kfnode configuration, and the value is of type `part_config/0. The following parameters can be configured:

Example usage

   {map, kflow_postgres, #{ database => #{ host     => "localhost"
                                         , user     => "kflow"
                                         , password => "123"
                                         , database => "postgres"
                                         , port     => 5432
                                         }
                          , table  => "foo_table"
                          , fields => [foo, bar, baz]
                          , keys   => [foo]
                          , partitioning => #{days => 10, retention => 3, index_fields => [bar]}
                          }}

Data Types

config()

config() = #{database := epgsql:connect_opts(), init_count => non_neg_integer(), fields := [field()], keys => [field()], table := list() | binary(), field_mappings => field_mappings(), partitioning => part_config()}

field()

field() = atom() | list() | binary()

field_mappings()

field_mappings() = #{field() => field()}

part_config()

part_config() = #{days := non_neg_integer(), retention := non_neg_integer(), index_fields => [field()], n_part_ahead => non_neg_integer(), n_part_behind => non_neg_integer()}

Function Index

ensure_partitions/1

Function Details

ensure_partitions/1

ensure_partitions(Config::config()) -> ok


Generated by EDoc