Hi Offray, 

You’re correct that ReStore can’t store that kind of mixed dictionary directly. 
You could store the entire STON text as one string and reify it on read, though 
that would mean you can’t easily query on the metadata. 

A compromise solution would be to define objects and slots for the key data 
you’d need to query on and a STON string for the residue. This could be a 
better solution anyway as excessive/complex Dictionaries can be a sign that you 
need to define a new class/classes. For your particular project this would 
depend on how similar the metadata is between tweets - if there’s not much 
commonality then a Dictionary approach may be more appropriate. 

Hope this helps,

John



> On 5 Apr 2022, at 20:07, Offray Vladimir Luna Cárdenas 
> <offray.l...@mutabit.com> wrote:
> 
> Hi all,
> 
> First of all, despite of being on a non-directly related matter with my 
> question, congrats of Pharo 10.
> 
> We (as now we have 2 active Smalltalkers in my country... Yay!) are creating 
> a civic tech project with Pharo/Lepiter and we would like to store some Tweet 
> metadata coming from Nitter[1]. As we're dealing with the differences between 
> the official Twitter API and the unofficial Nitter one, we put the metadata 
> we need in a dictionary that has several kinds of objects, from ordered 
> collections to other dictionaries. 
> [1] https://nitter.net/about <https://nitter.net/about>
> Currently if we serialize a Tweet object in STON, we get this:
> 
> Tweet { #created : 'Tue, 05 Apr 2022 12:37:56 GMT', #text : '
> 
> [ANN] Pharo 10 Released: pharo.org/news/pharo10-relea… 
> <https://pharo.org/news/pharo10-released>\n', #id : '1511322244353597443', 
> #user : NitterUser { #userName : 'pharoproject', #profileImageUrl : URL [ 
> 'http://nitter.42l.fr/pic/pbs.twimg.com/profile_images/541743734/icone-pharo-1_400x400.png
>  
> <http://nitter.42l.fr/pic/pbs.twimg.com/profile_images/541743734/icone-pharo-1_400x400.png>'
>  ] }, #metadata : { 'queries' : OrderedCollection [ { 'date' : DateAndTime [ 
> '2022-04-05T13:36:58.546011-05:00' ], 'parameters' : 
> 'https://nitter.42l.fr/pharoproject <https://nitter.42l.fr/pharoproject>' } 
> ], 'timelines' : { 'pharoproject' : '1511048498703126529' } } }
> As you can see, the metadata slot contains a dictionary with mixed classes of 
> objects. But I read in the ReStore manual[2] (pg 14):
> 
> """
> 
> Like other collections, the class of elements for both key and value can be 
> any other
> persistent class, and will be the same for all elements of that collection 
> (except in the case of
> inheritance).
> """
> So, is ReStore unable to store metadata dictionaries like the one described 
> in the previous STON code? if this is possible, how can I define it in the 
> Tweet class>>reStoreDefinition? 
> For the moment, I'm going to create a explicit "timelines" slot to store what 
> was being stored at the #timelines key of the metadata dictionary. But, as 
> metadata increases, instead of moving variables previously inside of a 
> dictionary as explicit slots of an object, I think that having a explicit way 
> of storing dictionaries with different kinds of objects, in contrast with 
> only uniform ones, would be needed (but I don't know if this is in the design 
> scope of ReStore).
> 
> BTW, Lepiter has allow us to build a pretty fluent interface to browser 
> Twitter/Nitter profiles and messages. Here it is how such UI looks for 
> browsing last @pharoproject tweets:
> 
> https://i.imgur.com/bxFze1g.png <https://i.imgur.com/bxFze1g.png>
> Any help on how to use ReStore in storing mixed dictionaries is appreciated.
> 
> Thanks,
> 
> Offray

Reply via email to