
\begin{DoxyItemize}
\item infos = Information about the directoryvalue plugin is in keys below
\item infos/author = René Schwaiger \href{mailto:sanssecours@me.com}{\tt sanssecours@me.\+com}
\item infos/licence = B\+SD
\item infos/needs =
\item infos/provides =
\item infos/recommends =
\item infos/placements = postgetstorage presetstorage
\item infos/status = maintained unittest nodep preview
\item infos/metadata =
\item infos/description = This plugin converts directory keys to leaf keys in the set direction
\end{DoxyItemize}\hypertarget{md_src_plugins_directoryvalue_README_src_plugins_directoryvalue_README_md}{}\section{Directory Value}\label{md_src_plugins_directoryvalue_README_src_plugins_directoryvalue_README_md}
\subsection*{Introduction}

The Directory Value plugin converts


\begin{DoxyEnumerate}
\item directory (non-\/leaf) keys to leaf keys in the “set” direction, and
\item converts them back to directory keys in the “get” direction.
\end{DoxyEnumerate}

A directory key is a key that has children. For example in the key set\+:


\begin{DoxyCode}
user/grandparent                = Grandparent
user/grandparent/leaf           = Leaf
user/grandparent/parent         = Parent
user/grandparent/parent/child   = Child
user/mother                     = Mother
user/mother/daughter            = Daughter
user/mother/son                 = Son
\end{DoxyCode}


the keys


\begin{DoxyCode}
user/grandparent
user/grandparent/parent
user/mother
\end{DoxyCode}


represent directory keys, while the keys


\begin{DoxyCode}
user/grandparent/leaf
user/grandparent/parent/child
user/mother/daughter
user/mother/son
\end{DoxyCode}


are leaf keys. You can easily check this by drawing the key set in the form of a rooted tree\+:


\begin{DoxyCode}
             user
      /               \(\backslash\)
  granparent        mother
  /      |          /    \(\backslash\)
leaf  parent    daughter son
         |
       child
\end{DoxyCode}


. The Directory Value plugin converts all directory keys to leaf keys in the “set” direction by adding new keys with the postfix {\ttfamily \+\_\+\+\_\+\+\_\+dirdata}. Theses keys then store the old value of their parent keys


\begin{DoxyCode}
user/grandparent                    =
user/grandparent/\_\_\_dirdata         = Grandparent
user/grandparent/leaf               = Leaf
user/grandparent/parent             =
user/grandparent/parent/\_\_\_dirdata  = Parent
user/grandparent/parent/child       = Child
user/mother                         =
user/mother/\_\_\_dirdata              = Mother
user/mother/daughter                = Daughter
user/mother/son                     = Son
\end{DoxyCode}


. You might ask why we need the Directory Value plugin at all. The reason why we created this plugin is that some storage plugins like \hyperlink{md_src_plugins_yajl_README_src_plugins_yajl_README_md}{`yajl`} or \hyperlink{md_src_plugins_yajl_README_src_plugins_yajl_README_md}{`yamlcpp`} are only able to save values inside leaf keys. By loading the Directory Value plugin these storage plugins are also able to represent directory values properly.

\subsubsection*{Array Values}

The Directory value plugin also converts array values. Let us take a look at an example key set\+:


\begin{DoxyCode}
user/array    = Array Value
user/array/#0 = Firt Value
user/array/#1 = Second Value
user/array/#2 = Third Value
\end{DoxyCode}


. The plugin {\bfseries does not} convert this key set into\+:


\begin{DoxyCode}
user/array            =
user/array/\_\_\_dirdata = Array Value
user/array/#0         = First Value
user/array/#1         = Second Value
user/array/#2         = Third Value
\end{DoxyCode}


, since then {\ttfamily user/array} {\bfseries would not be an array} any more. Instead the plugin inserts a new element at index 0 with the {\bfseries value prefix} {\ttfamily \+\_\+\+\_\+\+\_\+dirdata\+:}\+:


\begin{DoxyCode}
user/array            =
user/array/#0         = \_\_\_dirdata: Array Value
user/array/#1         = First Value
user/array/#2         = Second Value
user/array/#3         = Third Value
\end{DoxyCode}


. This way a storage plugin such as Y\+A\+JL or Y\+A\+ML C\+PP are still able to store {\ttfamily user/array} as an array.

{\bfseries Remark\+:} The plugin only converts array parents that store {\bfseries string values}.

\subsection*{Usage}

To mount the plugin use the command\+:

``{\ttfamily  $<$h1$>$Mount plugin at}user/tests/directoryvalue` sudo kdb mount config.\+file user/tests/directoryvalue directoryvalue 
\begin{DoxyCode}
. To unmount the plugin use the command
\end{DoxyCode}
 sudo kdb umount user/tests/directoryvalue 
\begin{DoxyCode}
.

## Example
\end{DoxyCode}
 \section*{Mount plugin}

sudo kdb mount config.\+file user/tests/directoryvalue directoryvalue

\section*{Add a directory value}

kdb set user/tests/directoryvalue/harold \textquotesingle{}Father of Sponge\+Bob Square\+Pants\textquotesingle{} \section*{Add a leaf value}

kdb set user/tests/directoryvalue/harold/spongebob \textquotesingle{}I am ready!\textquotesingle{}

\section*{Add an array}

kdb set user/tests/directoryvalue/patrick Star kdb set user/tests/directoryvalue/patrick/\#0 \textquotesingle{}Being grown-\/up is boring. Besides, I don’t get Jazz.\textquotesingle{}

\section*{Since the plugin converts values back in the get direction}

\section*{a user of the database will not notice any changes.}

kdb ls user/tests/directoryvalue \#$>$ user/tests/directoryvalue/harold \#$>$ user/tests/directoryvalue/harold/spongebob \#$>$ user/tests/directoryvalue/patrick \#$>$ user/tests/directoryvalue/patrick/\#0

kdb get user/tests/directoryvalue/harold \#$>$ Father of Sponge\+Bob Square\+Pants kdb get user/tests/directoryvalue/harold/spongebob \#$>$ I am ready!

kdb get user/tests/directoryvalue/patrick \#$>$ Star kdb get user/tests/directoryvalue/patrick/\#0 \#$>$ Being grown-\/up is boring. Besides, I don’t get Jazz.

\section*{Retrieve index of last element in array.}

\section*{This also works if the storage plugin does not store this index.}

kdb getmeta user/tests/directoryvalue/patrick array \#$>$ \#0

\section*{Undo changes to the key database}

kdb rm -\/r user/tests/directoryvalue sudo kdb umount user/tests/directoryvalue ```

\section*{Limitations}


\begin{DoxyItemize}
\item {\bfseries Escaping} is currently {\bfseries not possible}. If you use the Directory Value plugin you can not
\begin{DoxyItemize}
\item use the name {\ttfamily \+\_\+\+\_\+\+\_\+dirdata} as the last part of a normal key,
\item use {\ttfamily \+\_\+\+\_\+\+\_\+dirdata\+:} at the beginning of a normal value in the first array element
\end{DoxyItemize}

!
\item The plugin is \href{https://issues.libelektra.org/2281}{\tt quite slow}. 
\end{DoxyItemize}