How to set up transition fields with Korma

I use Clojure with korma to store Clojure maps in a Mysql database, for example, to store maps with this structure:

(defentity users (table :user) (entity-fields :email :password :name)) 

In a table with four columns, id (implicitly defined), email , password and name .

So, when I call this piece of code, everything works fine:

 (insert users (values {:email " john@example.com " :password "____hashed_passw___" :name "J"})) 

The problem is that my cards may contain some keys that do not have corresponding columns in the database (and I do not want to store these values). For instance:

 (insert users (values {:email " john@example.com " :password "____hashed_passw___" :name "J" :something "else"})) 

Would MySQLSyntaxErrorException Unknown column 'something' in 'field list' error.

Ideally, I would like to know if there is an option in Poop in order to ignore the extra keys present on the map. The problem can be solved with dissoc - all of them when saved, but I would prefer to find out if there is a built-in way to do this before I do it (or any other better idea).

+4
source share
1 answer

No, you need to remove additional key / value pairs from the card. Perhaps Poop could have been done to remove them based on impartiality.

I suggest you either translate it to https://github.com/korma/Korma as a function request, or simply add it yourself. Chris Granger, the companion, is easy to talk to and is likely to consider your idea.

+2
source

Source: https://habr.com/ru/post/1437568/


All Articles