
\begin{DoxyItemize}
\item infos = Information about the csvstorage plugin is in keys below
\item infos/author = Thomas Waser \href{mailto:thomas.waser@libelektra.org}{\texttt{ thomas.\+waser@libelektra.\+org}}
\item infos/licence = BSD
\item infos/provides = storage/csv
\item infos/needs =
\item infos/recommends =
\item infos/placements = getstorage setstorage
\item infos/status = unittest nodep libc configurable limited
\item infos/description = parses CSV files
\end{DoxyItemize}\hypertarget{md_src_plugins_csvstorage_README_src_plugins_csvstorage_README_md}{}\doxysection{Introduction}\label{md_src_plugins_csvstorage_README_src_plugins_csvstorage_README_md}
This plugin allows you to read and write CSV files using Elektra. It aims to be compatible with RFC 4180. Rows and columns are written using Elektra\textquotesingle{}s arrays ({\ttfamily \#0}, {\ttfamily \#1},..). By configuring the plugin you can give columns a name.\hypertarget{md_src_plugins_csvstorage_README_autotoc_md119}{}\doxysection{Configuration}\label{md_src_plugins_csvstorage_README_autotoc_md119}
{\ttfamily delimiter} Tells the plugin what delimiter is used in the file. The default delimiter is {\ttfamily ,} and will be used if {\ttfamily delimiter} is not set.

{\ttfamily header} Tells the plugin to use the first line as a header if it is set to {\ttfamily colname}. The columns will get the corresponding names. Skip the first line if it is set to {\ttfamily skip} or treat the first line as a record if it is set to {\ttfamily record}. If {\ttfamily header} is not set, or set to {\ttfamily record}, the columns get named \#0,\#1,... (array key naming)

{\ttfamily columns} If this key is set the plugin will yield an error for every file that doesn\textquotesingle{}t have exactly the amount of columns as specified in {\ttfamily columns}.

{\ttfamily columns/names} Sets the column names. Only usable in combination with the {\ttfamily columns} key. The number of subkeys must match the number of columns. Conflicts with usage of {\ttfamily header}.

{\ttfamily columns/index} Specifies which column should be used to index records instead of the record number.

{\ttfamily export=,export/$<$column name$>$=} Export column {\ttfamily column name}\+:


\begin{DoxyItemize}
\item The key {\ttfamily export} must be present, additionally to {\ttfamily export/$<$column name$>$}
\item Also multiple column names can be given for different columns to export.
\begin{DoxyItemize}
\item Then {\ttfamily delimiter} will be used as delimiter ({\ttfamily ,} as default).
\item The order depends on the alphabetic order of the column names. Use `awk -\/F',\textquotesingle{} \textquotesingle{}BEGIN\{OFS=\char`\"{},\char`\"{}\} \{print \$2, \$1, \$3\}\textquotesingle{}\`{} or similar to reorder.
\item Unknown column names are ignored.
\end{DoxyItemize}
\end{DoxyItemize}\hypertarget{md_src_plugins_csvstorage_README_autotoc_md120}{}\doxysection{Examples}\label{md_src_plugins_csvstorage_README_autotoc_md120}
First line should determine the headers\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{kdb mount test.csv /csv csvstorage \(\backslash\)}
\DoxyCodeLine{  "{}delimiter=;,header=colname,columns=2,columns/names,columns/names/\#0=col0Name,columns/names/\#1=col1Name"{}}

\end{DoxyCode}
\hypertarget{md_src_plugins_csvstorage_README_autotoc_md121}{}\doxysubsection{Usage}\label{md_src_plugins_csvstorage_README_autotoc_md121}
The example below shows how you can use this plugin to read and write CSV files.


\begin{DoxyCode}{0}
\DoxyCodeLine{\# Mount plugin to `user:/tests/csv`}
\DoxyCodeLine{\# We use the column names from the first line of the}
\DoxyCodeLine{\# config file as key names}
\DoxyCodeLine{sudo kdb mount config.csv user:/tests/csv csvstorage  "{}header=colname,columns/names/\#0=col0Name,columns/names/\#1=col1Name"{}}
\DoxyCodeLine{}
\DoxyCodeLine{\# Add some data}
\DoxyCodeLine{printf 'band,album\(\backslash\)n'                           >> `kdb file user:/tests/csv`}
\DoxyCodeLine{printf 'Converge,All We Love We Leave Behind\(\backslash\)n' >> `kdb file user:/tests/csv`}
\DoxyCodeLine{printf 'mewithoutYou,Pale Horses\(\backslash\)n'             >> `kdb file user:/tests/csv`}
\DoxyCodeLine{printf 'Kate Tempest,Everybody Down\(\backslash\)n'          >> `kdb file user:/tests/csv`}
\DoxyCodeLine{}
\DoxyCodeLine{kdb ls user:/tests/csv}
\DoxyCodeLine{\#> user:/tests/csv/\#0}
\DoxyCodeLine{\#> user:/tests/csv/\#0/album}
\DoxyCodeLine{\#> user:/tests/csv/\#0/band}
\DoxyCodeLine{\#> user:/tests/csv/\#1}
\DoxyCodeLine{\#> user:/tests/csv/\#1/album}
\DoxyCodeLine{\#> user:/tests/csv/\#1/band}
\DoxyCodeLine{\#> user:/tests/csv/\#2}
\DoxyCodeLine{\#> user:/tests/csv/\#2/album}
\DoxyCodeLine{\#> user:/tests/csv/\#2/band}
\DoxyCodeLine{\#> user:/tests/csv/\#3}
\DoxyCodeLine{\#> user:/tests/csv/\#3/album}
\DoxyCodeLine{\#> user:/tests/csv/\#3/band}
\DoxyCodeLine{}
\DoxyCodeLine{\# The first array element contains the column names}
\DoxyCodeLine{kdb get user:/tests/csv/\#0/band}
\DoxyCodeLine{\#> band}
\DoxyCodeLine{kdb get user:/tests/csv/\#0/album}
\DoxyCodeLine{\#> album}
\DoxyCodeLine{}
\DoxyCodeLine{\# Retrieve data from the last entry}
\DoxyCodeLine{kdb get user:/tests/csv/\#3/album}
\DoxyCodeLine{\#> Everybody Down}
\DoxyCodeLine{kdb get user:/tests/csv/\#3/band}
\DoxyCodeLine{\#> Kate Tempest}
\DoxyCodeLine{}
\DoxyCodeLine{\# Change an existing item}
\DoxyCodeLine{kdb set user:/tests/csv/\#1/album 'You Fail Me'}
\DoxyCodeLine{\# Retrieve the new item}
\DoxyCodeLine{kdb get user:/tests/csv/\#1/album}
\DoxyCodeLine{\#> You Fail Me}
\DoxyCodeLine{}
\DoxyCodeLine{\# The plugin stores the index of the last column}
\DoxyCodeLine{\# in all of the parent keys.}
\DoxyCodeLine{kdb get user:/tests/csv/\#0}
\DoxyCodeLine{\#> \#1}
\DoxyCodeLine{kdb get user:/tests/csv/\#1}
\DoxyCodeLine{\#> \#1}
\DoxyCodeLine{kdb get user:/tests/csv/\#2}
\DoxyCodeLine{\#> \#1}
\DoxyCodeLine{kdb get user:/tests/csv/\#3}
\DoxyCodeLine{\#> \#1}
\DoxyCodeLine{}
\DoxyCodeLine{\# The configuration file reflects the changes}
\DoxyCodeLine{kdb file user:/tests/csv | xargs cat}
\DoxyCodeLine{\#> album,band}
\DoxyCodeLine{\#> You Fail Me,Converge}
\DoxyCodeLine{\#> Pale Horses,mewithoutYou}
\DoxyCodeLine{\#> Everybody Down,Kate Tempest}
\DoxyCodeLine{}
\DoxyCodeLine{\# Undo changes to the key database}
\DoxyCodeLine{kdb rm -\/r user:/tests/csv}
\DoxyCodeLine{sudo kdb umount user:/tests/csv}

\end{DoxyCode}
\hypertarget{md_src_plugins_csvstorage_README_autotoc_md122}{}\doxysection{Column as index}\label{md_src_plugins_csvstorage_README_autotoc_md122}

\begin{DoxyCode}{0}
\DoxyCodeLine{kdb mount config.csv /tests/csv csvstorage "{}delimiter=;,header=colname,columns/index=IMDB"{}}
\DoxyCodeLine{}
\DoxyCodeLine{printf 'IMDB;Title;Year\(\backslash\)n'                          >> `kdb file /tests/csv`}
\DoxyCodeLine{printf 'tt0108052;Schindler´s List;1993\(\backslash\)n'          >> `kdb file /tests/csv`}
\DoxyCodeLine{printf 'tt0110413;Léon: The Professional;1994\(\backslash\)n'    >> `kdb file /tests/csv`}
\DoxyCodeLine{}
\DoxyCodeLine{kdb ls /tests/csv}
\DoxyCodeLine{\#> user:/tests/csv/tt0108052}
\DoxyCodeLine{\#> user:/tests/csv/tt0108052/IMDB}
\DoxyCodeLine{\#> user:/tests/csv/tt0108052/Title}
\DoxyCodeLine{\#> user:/tests/csv/tt0108052/Year}
\DoxyCodeLine{\#> user:/tests/csv/tt0110413}
\DoxyCodeLine{\#> user:/tests/csv/tt0110413/IMDB}
\DoxyCodeLine{\#> user:/tests/csv/tt0110413/Title}
\DoxyCodeLine{\#> user:/tests/csv/tt0110413/Year}
\DoxyCodeLine{}
\DoxyCodeLine{kdb get /tests/csv/tt0108052/Title}
\DoxyCodeLine{\#> Schindler´s List}
\DoxyCodeLine{}
\DoxyCodeLine{kdb rm -\/r /tests/csv}
\DoxyCodeLine{sudo kdb umount /tests/csv}

\end{DoxyCode}
\hypertarget{md_src_plugins_csvstorage_README_autotoc_md123}{}\doxysection{Export filter}\label{md_src_plugins_csvstorage_README_autotoc_md123}

\begin{DoxyCode}{0}
\DoxyCodeLine{kdb mount config.csv /tests/csv csvstorage "{}delimiter=;,header=colname,columns/index=IMDB"{}}
\DoxyCodeLine{}
\DoxyCodeLine{printf 'IMDB;Title;Year\(\backslash\)n'                          >> `kdb file /tests/csv`}
\DoxyCodeLine{printf 'tt0108052;Schindler´s List;1993\(\backslash\)n'          >> `kdb file /tests/csv`}
\DoxyCodeLine{printf 'tt0110413;Léon: The Professional;1994\(\backslash\)n'    >> `kdb file /tests/csv`}
\DoxyCodeLine{}
\DoxyCodeLine{kdb export /tests/csv csvstorage -\/c "{}delimiter=;,header=colname,columns/index=IMDB,export=,export/IMDB=,export/Title="{}}
\DoxyCodeLine{\#> IMDB;Title}
\DoxyCodeLine{\#> tt0108052;Schindler´s List}
\DoxyCodeLine{\#> tt0110413;Léon: The Professional}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{kdb export /tests/csv csvstorage -\/c "{}delimiter=;,header=colname,columns/index=IMDB,export=,export/IMDB=,export/Year="{}}
\DoxyCodeLine{\#> IMDB;Year}
\DoxyCodeLine{\#> tt0108052;1993}
\DoxyCodeLine{\#> tt0110413;1994}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{kdb rm -\/r /tests/csv}
\DoxyCodeLine{sudo kdb umount /tests/csv}

\end{DoxyCode}
\hypertarget{md_src_plugins_csvstorage_README_autotoc_md124}{}\doxysubsection{Limitations}\label{md_src_plugins_csvstorage_README_autotoc_md124}

\begin{DoxyItemize}
\item Does not work on file streams (e.\+g. {\ttfamily kdb import} without file)
\item When using csvstorage for exporting, all parent keys must be present (see \href{https://issues.libelektra.org/2304}{\texttt{ https\+://issues.\+libelektra.\+org/2304}}) 
\end{DoxyItemize}