# Programatically modifying Datalog query

**URL:** https://forum.datomic.com/t/programatically-modifying-datalog-query/491
**Category:** General
**Created:** [June 27, 2018, 7:23am UTC](https://forum.datomic.com/t/programatically-modifying-datalog-query/491 "2018-06-27T07:23:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mayank](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/mayank/32/183_2.png) [@Mayank](https://forum.datomic.com/u/Mayank)
#### Post date: [June 27, 2018, 7:23am UTC](https://forum.datomic.com/t/programatically-modifying-datalog-query/491/1 "2018-06-27T07:23:46Z")

</div>

Hi All,

I am receiving the stringified datalog query as one of the values inside a JSON request. Before executing the query, I need to modify it in my Clojure code to add some more conditions. I was unsure about the approach that I should take - should I proceed with string concatenations or should I convert the query into Clojure data structure and then proceed with modifying that data structure. I tried to search for some examples but wasn’t able to find any. Could you please suggest me what would be the better approach.

Thanks,  
Mayank

---

<div class="post-metadata">

### Author: ![timgilbert](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/timgilbert/32/68_2.png) [@timgilbert](https://forum.datomic.com/u/timgilbert)
#### Post date: [June 27, 2018, 4:16pm UTC](https://forum.datomic.com/t/programatically-modifying-datalog-query/491/2 "2018-06-27T16:16:25Z")

</div>

Personally, I’d convert it into a Clojure data structure as soon as possible. Once it’s in that format, you can use `spec` or other tools to validate it, manipulate the structure, etc.

You should also think about the security implications of allowing the client to send datalog over directly, as it can open you up to similar problems as SQL injection attacks. One alternative approach is that you can store the actual query on your server and then just have the client send the name of the query and any parameters over.

---

<div class="post-metadata">

### Author: ![marshall](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/marshall/32/48_2.png) [@marshall](https://forum.datomic.com/u/marshall)
#### Post date: [June 27, 2018, 5:05pm UTC](https://forum.datomic.com/t/programatically-modifying-datalog-query/491/3 "2018-06-27T17:05:24Z")

</div>

I agree that I would tend toward converting it into data prior to manipulation.

Also, Tim’s warnings regarding security are quite right - be sure you know what is in the code before you allow it to be executed.

---

<div class="post-metadata">

### Author: ![Mayank](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/mayank/32/183_2.png) [@Mayank](https://forum.datomic.com/u/Mayank)
#### Post date: [June 29, 2018, 1:23pm UTC](https://forum.datomic.com/t/programatically-modifying-datalog-query/491/4 "2018-06-29T13:23:59Z")

</div>

Thanks for the suggestions
