5

I need to create dynamic query clauses depending on user input, i.e. dynamically specifying the column within a query. All the examples are of the form

.where(_.id eqs myUuid)

however I need sth along the lines of

.where('id' eqs myUuid)

which is not possible. Is there any way to specify the columns of queries dynamically using phantom-dsl?

sinel
  • 51
  • 3

1 Answers1

1

Phantom does not allow for arbitrary models or wide rows, it's unfortunately not very realistic to be able to build an object model based on that. If you want wide rows, phantom won't be able to do much for you at this point in time, we are working hard to deliver a competitive solution there too but it's not easy, phantom's superpower comes from the object model and the autocompletion/typesafety/auto-migrations that result from that.

If you are simply worried about migrations and the ability to change structures on the fly and sync with Cassandra, we are releasing a very very advanced automated migration capability as part of phantom-pro, the commercial version of phantom.

flavian
  • 28,161
  • 11
  • 65
  • 105
  • Thanks for your answer but it looks like you misunderstood my question - the model is fixed. For example, I have an object with fixed fields x, y, and z. If user input is for updating x=2, then I need to generate modify(_.x=2), or for x=3 and y=5, I need to generate modify(_.x=3).and(_.y=5) dynamically. If my object has many fixed fields, writing a fixed method for each combination is not feasible. It looks like the datastax java driver has a QueryBuilder object with a set(String name, Object value) method to do this, but I am asking how to do it with phantom-dsl in scala? – sinel Mar 16 '16 at 04:23
  • You can do the same with phantom, I will write up something. – flavian Mar 16 '16 at 10:19
  • Thanks - nice to know it can be done, but I am stuck here since I cannot figure out how from either the docs or the examples in your github repo. If you are short on time to put together an example, can you at least give me a quick pointer on how so I can try myself. – sinel Mar 17 '16 at 15:06
  • @sinel The simple way is to update everything every time, this is just to get you unstuck. Just update with the existing value every time, it's not actually much overhead. Not ideal I know, but it will buy you time. – flavian Mar 17 '16 at 15:14
  • Thanks for the quick reply. From your comment, I understand there is a better way of doing it and you will provide that info later when you have time, so I will keep this question open. If not, please let me know and I will accept this as the answer. – sinel Mar 17 '16 at 15:47