# Get all keys using Irmin\_git

**URL:** <https://discuss.ocaml.org/t/get-all-keys-using-irmin-git/5798>\
**Category:** Learning\
**Tags:** irmin\
**Created:** [May 18, 2020, 11:15am UTC](https://discuss.ocaml.org/t/get-all-keys-using-irmin-git/5798 "2020-05-18T11:15:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleridia](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@Aleridia](https://discuss.ocaml.org/u/Aleridia)\
**Post date:** [May 18, 2020, 11:15am UTC](https://discuss.ocaml.org/t/get-all-keys-using-irmin-git/5798/1 "2020-05-18T11:15:48Z")

</div>

Hi,

I’m implementing a “database” using the irmin\_git’s package and irmin\_unix’s package, but I can’t figure out how to **get all the branch’s keys**.

I found the [find\_all](https://mirage.github.io/irmin/irmin-unix/Irmin_unix/Git/FS/KV/Tree/index.html#val-find_all) function but as I see it’s like a [find](https://mirage.github.io/irmin/irmin-unix/Irmin_unix/Git/FS/KV/Tree/index.html#val-find) without metadata.

I have searched in the documentation but it’s pretty dense and I can’t find out which function can do the job for me.

Can you give me any clue to get what I want ?

I’m using Irmin 1.4.0 and Irmin\_unix 1.3.3.

Here is my code :

```auto
module Git_store = Irmin_unix.Git.FS.KV(Irmin.Contents.String)
let git_config = Irmin_git.config ~bare:true "./irmin/"

let master config = Git_store.Repo.v config >>= Git_store.master
let branch config name = Git_store.Repo.v config >>= fun repo -> Git_store.of_branch repo name

(* de a vers b *)
let irmin = Git_store.Repo.v git_config >>= Git_store.master >>= fun t ->
           Git_store.find_all t [] >>= fun c ->
           (match c with
           | Some (b,_) -> Printf.printf "Read: %s \n%!" b ; Lwt.return_unit
           | None -> Printf.printf "Nop"; Lwt.return_unit)
           >>= fun () ->
           Server.respond_string ~status:`OK ~body:"OK" ()

```

Thanks in advance for your responses,

---

<div class="post-metadata">

**Author:** ![dinosaure](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dinosaure/32/16_2.png) [@dinosaure](https://discuss.ocaml.org/u/dinosaure)\
**Post date:** [May 18, 2020, 1:44pm UTC](https://discuss.ocaml.org/t/get-all-keys-using-irmin-git/5798/2 "2020-05-18T13:44:12Z")

</div>

> [@Aleridia](#):
>
> I’m using Irmin 1.4.0 and Irmin\_unix 1.3.3.

First, it seems that you look into the documentation of `irmin.2.0.0` where it seems that you use `irmin.1.4.0`.

Then, I’m not sure to understand what you want but from what I know, your type `t` represents a [graph](https://en.wikipedia.org/wiki/Graph_(abstract_data_type)) or more specially a [tree](https://en.wikipedia.org/wiki/Tree_(data_structure)) with nodes and leafs. To be able to get all keys of your type `t`, you must walk inside the tree.

Such function exists with [`fold`](https://mirage.github.io/irmin/irmin-unix/Irmin_unix/Git/FS/KV/Tree/index.html#val-fold) which will _walk_ recursively into your tree. The given tree should be the _root_ tree of your branch which can be get with [tree](https://mirage.github.io/irmin/irmin-unix/Irmin_unix/Git/FS/KV/index.html#val-tree).

More concretely with Git, a tree is a directory which can have some `blobs` (_leafs_) and the type `t` can be considered as a _commit_.

---

<div class="post-metadata">

**Author:** ![Aleridia](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@Aleridia](https://discuss.ocaml.org/u/Aleridia)\
**Post date:** [May 18, 2020, 2:31pm UTC](https://discuss.ocaml.org/t/get-all-keys-using-irmin-git/5798/3 "2020-05-18T14:31:50Z")

</div>

Thank you for your help !

> [@dinosaure](#):
>
> First, it seems that you look into the documentation of `irmin.2.0.0` where it seems that you use `irmin.1.4.0` .

I know but these functions doesn’t change between the 1.4.0 and the 2.0.0 version. I’m using the offline documentation with odig.

> [@dinosaure](#):
>
> Then, I’m not sure to understand what you want

I’m a beginner with Irmin so I am sorry if my demand wasn’t clear.  
That I want is to get all the keys of the current branch.  
For example, when I add data with this :  
`Git_store.Tree.add tree ["test1"] user_1`  
`Git_store.Tree.add tree ["test2"] user_2`  
I am searching a way to get a `String list` like this `["test1";"test2";...]`

> [@dinosaure](#):
>
> Such function exists with [`fold`](https://mirage.github.io/irmin/irmin-unix/Irmin_unix/Git/FS/KV/Tree/index.html#val-fold) which will _walk_ recursively into your tree. The given tree should be the _root_ tree of your branch which can be get with [tree](https://mirage.github.io/irmin/irmin-unix/Irmin_unix/Git/FS/KV/index.html#val-tree).

As I understand, the `fold` function will execute my function `f` if it got a leaf, and if not (So it’s a node) it will recursively call itself by passing the node.  
And the function `f` take `key`, `contents` and `'a` in parameters which will be given by `fold`. For example, can the `key` and the `content` be the `["test1"]` and `user_1` I added before ?

Thanks for your reply
