relevance / diametric

Diametric is a library for building schemas, queries, and transactions for Datomic from Ruby objects.
MIT License
169 stars 28 forks source link

Database functions? #28

Open Mori opened 11 years ago

Mori commented 11 years ago

How do you use database functions / transaction functions written in ruby, via diametric?

avescodes commented 11 years ago

As far as I know it is not possible to use database functions written in Ruby at the moment (at least in the REST persistence API.) (Unless @yokolet has made the enhancement in the last few weeks).

Honestly I'm not sure if the Datomic REST API even exposes this functionality. It would certainly be possible to implement it in Peer-mode, but REST is always another story (as it is with most "lower-level" features of Datomic).

yokolet commented 11 years ago

Hello @Mori . Thanks for trying Diametric out.

You can use database function on diametric. But, it is not straightforward in this version. It will be something like below.

If you are using peer connection:

query = [Java::Datomic::Util.list(":db.fn/retractEntity", dbid)]
Peer.class.connection.transact(query).get

If you are using rest connection:

query = [[:"db.fn/retractEntity", dbid.to_i]]
REST.class.transact(query)

I used the function to delete an entity in Diametric. Perhaps, you can use functions like this, but I haven't tried yet from a program that uses Diametric. So, if you have a chance, try this and report the result. Your attempt will help other users as well.