sanity-clause icon indicating copy to clipboard operation
sanity-clause copied to clipboard

Automatic persistence / serialization

Open Ambrevar opened this issue 6 years ago • 3 comments

Since sanity-clause supports serialization, would it be possible to have it automatically serialize and persist an object to a file on modification? More or less like ubiquitous does it?

Should we go down this road, wouldn't sanity-clause completely supersede Ubiquitous? What about mering the efforts?

Ambrevar avatar Sep 01 '19 11:09 Ambrevar

Hi @Ambrevar , thanks for the interest!

I'm not familiar with ubiquitous, but it looks like there's room for the two libraries to coexist - sanity-clause could validate data and ubiquitious persists it. Maybe if I make something useful enough, it could be used by ubiquitous as the serialization layer. It looks like perhaps it already supports serializing lisp objects, so you might be able to create validated objects and load/save them already!

But also - I have added a basic interface for serializing/deserializing things to sanity-clause. I don't think adding the persistence logic feels in-scope of the library to me, but I imagine you could do something with (setf slot-value-using-class), maybe an after method that serializes for you?

(defmethod :after (setf slot-value-using-class) (new-value (class my-class) object slotd)
  (write-object-to-file object))

If you come up with something you think is sufficiently useful, I'd be happy to make/accept a helper package that integrates sanity-clause with another library.

fisxoj avatar Sep 02 '19 04:09 fisxoj

This could work, but then the next obvious goal would be to have such :after methods automatically set for all slots :)

To clarify: setting any slot of such a class would automatically be persisted to disk. Very much in the line of what some database managers do (like Mito).

Could be doable with a meta-class, what do you think?

With regard to the coexistence between sanity-clause and ubiquitous: Sanity-clause can a expose a configurable meta-class which sets the setf :after method to something the user decides, e.q. ubiquitous.

Would there still be room for sanity-clause's serialization layer then?

Ambrevar avatar Sep 02 '19 08:09 Ambrevar

By the way I tried

(defmethod (setf c2mop:slot-value-using-class) :after (new-value (class MY-CLASS) object slotd)
  (format t "Hacking ~a here" object))

and it does not seem to work. Hmmm, am I missing something?

Ambrevar avatar Sep 11 '19 16:09 Ambrevar