fiodorbaczynski

fiodorbaczynski

DataQuacker - a library for parsing non-sandboxed data like CSV files

Hi all,

I often find it tedious to parse CSV files. There are often complex rules for validating and transforming the data, matching columns by their indexes or header values, etc. Sometimes there is also a need to map one row in the CSV file into multiple elements in the output list, or to skip some rows or fields entirely based on their values. On top of that the resulting structure may have to be a nested map (in case of associations).

That’s why I created an Elixir library DataQuacker which features a simple DSL to describe the output structure along with how it should be mapped from the source and all the validation and transformation rules for each field or row.

You can find the library at Github and the docs at Hexdocs

To get a glimpse of the DSL, take a look at this relatively simple schema example from the docs:

defmodule StudentsSchema do
  use DataQuacker.Schema

  schema :students do
    field :first_name do
      source("first name")
    end

    field :last_name do
      source("last name")
    end

    field :age do
      transform(fn age ->
        case Integer.parse(age) do
          {age_int, _} -> {:ok, age_int}
          :error -> {:error, "Invalid value #{age} given"}
        end
      end)

      source("age")
    end

    field :favourite_subject do
      validate(fn subj -> subj in ["Maths", "Physics", "Programming"] end)

      source("favourite subject")
    end
  end
end

There are many more features, like arbitrarily nesting fields, matching columns with regex and custom functions, skipping rows, outputting multiple rows from one source row, injecting support data to validators, transformers, etc., using metadata to give error messages with detailed information about where an error occurred, and so on.

All of those are described in the docs along with examples and detailed explanations.

Another nice thing about the DSL is that it will give the user helpful errors at compile time if something is not right.

For now only CSV files and Elixir data is supported as the source out of the box, but anyone can write an adapter for the source they want to use, e.g. Google Sheets. It’s easy to write one, to learn more take a look at the Adapter behaviour in the docs).

Any feedback is greatly appreciated. Please tell me what you think, especially if you find any bugs, missing functionality or unclear / incomplete documentation.

Where Next?

Popular in Libraries Top

hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
New
deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
arkgil
Hi all! I’m happy to announce that Telemetry v0.3.0 is out! This release marks the conversion from Elixir to Erlang so that all the libr...
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
vic
Expat is a tiny experiment I did for extracting patterns and being able to reuse them (compose and share patterns between elixir librarie...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
KallDrexx
For a good number of months I've been working on creating a very basic RTMP live video streaming server. Now that I have a very, very ba...
New

Other popular topics Top

yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Sub Categories:

We're in Beta

About us Mission Statement