Re: Protocols for persistence - not sure about a few cases

2016-08-29 Thread jmckitrick
I read too quickly. I might need multi-methods after all, just like I used in Common Lisp. I want different types of persisted objects to have the same interface, if possible. Actually, I'm just experimenting with protocols, so I'm probably better off looking for a different use case. On Mon, Aug

Re: Protocols for persistence - not sure about a few cases

2016-08-29 Thread jmckitrick
Makes perfect sense. Thanks! On Mon, Aug 29, 2016 at 5:09 PM Jonathan Fischer wrote: > The most straightforward one: just make your protocols a thing that your > storage medium implements, instead of your records. E.g.: > > (defprotocol ThingStore > (load-item [store item-id]) > (load-items

Re: Protocols for persistence - not sure about a few cases

2016-08-29 Thread Jonathan Fischer
The most straightforward one: just make your protocols a thing that your storage medium implements, instead of your records. E.g.: (defprotocol ThingStore (load-item [store item-id]) (load-items [store item-ids]) (find-item [store item-name]) (save-item [store item])) (defrecord Databas

Re: Protocols for persistence - not sure about a few cases

2016-08-29 Thread Jonathan Fischer
Two options. The first, straightforward one: make the thing that's implementing the protocol the Storage, not in the individual things being stored. So something like: (defprotocol ItemStore (save-item [store item]) (load-items [store items])) etc. Second option: Clojure has multimethods t

Re: Protocols for persistence - not sure about a few cases

2016-08-28 Thread Shantanu Kumar
Considering the regular use-cases with records: Create - requires record without any auto-generated identifiers Retrieve - requires primary identifier or lookup parameters Update - requires record with primary identifier and updated fields Delete - requires primary identifier or lookup parameters

Protocols for persistence - not sure about a few cases

2016-08-28 Thread Jonathon McKitrick
I'm beginning a foray into protocols after coming from the Common Lisp world of multimethods. I'm using them initially to implement a consistent load/save API over the DB layer. It's pretty simple to have a Saveable protocol to save one object, because the first argument is a Record of the type