Saving a map to db field

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Saving a map to db field

Jussi Hirvi-2
L8.5. I never tried this before. I would like to store a map to a mysql
varchar field. The saving part goes well, but I don't find a way to read
the data back from the db as a map. I only get a string like: "map:
(23)=(69)". I can [process] that, but I don't find a way to get data out
of the [process] tag.

I tried for example to capture the db data in a variable:

  process('[var('a') = (' + field('mymap') + ')->first]');

It works to some extent - but $a -> type is string instead of pair!

Any advice?? I am slowly getting blind.

- Jussi
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Saving a map to db field

Jonathan Guthrie-3
I would use serialize and deserialize.

local('x' = map('a' = 1, 'b' = 2);
then save #x->serialize to the db column

When reading out:

local('y' = string(field('mydata'))->deserialize);

Untested syntax as it's from memory, so YMMV :)


On 2012-03-29, at 11:41 AM, Jussi Hirvi wrote:

> L8.5. I never tried this before. I would like to store a map to a mysql varchar field. The saving part goes well, but I don't find a way to read the data back from the db as a map. I only get a string like: "map: (23)=(69)". I can [process] that, but I don't find a way to get data out of the [process] tag.
>
> I tried for example to capture the db data in a variable:
>
> process('[var('a') = (' + field('mymap') + ')->first]');
>
> It works to some extent - but $a -> type is string instead of pair!
>
> Any advice?? I am slowly getting blind.
>
> - Jussi

Jono

----------------------------
Jonathan Guthrie
[hidden email]
LassoSoft Inc.

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Saving a map to db field

Jussi Hirvi-2
Thanks, I have forgot all about [serialize]. Neat!
- Jussi

On 29.3.2012 18.45, Jonathan Guthrie wrote:

> I would use serialize and deserialize.
>
> local('x' = map('a' = 1, 'b' = 2);
> then save #x->serialize to the db column
>
> When reading out:
>
> local('y' = string(field('mydata'))->deserialize);
>
> Untested syntax as it's from memory, so YMMV :)
>
>
> On 2012-03-29, at 11:41 AM, Jussi Hirvi wrote:
>
>> L8.5. I never tried this before. I would like to store a map to a mysql varchar field. The saving part goes well, but I don't find a way to read the data back from the db as a map. I only get a string like: "map: (23)=(69)". I can [process] that, but I don't find a way to get data out of the [process] tag.
>>
>> I tried for example to capture the db data in a variable:
>>
>> process('[var('a') = (' + field('mymap') + ')->first]');
>>
>> It works to some extent - but $a ->  type is string instead of pair!
>>
>> Any advice?? I am slowly getting blind.
>>
>> - Jussi
>
> Jono

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Saving a map to db field

Johan Solve
encode_json/decode_json is more compact and more compatible.

2012/3/29 Jussi Hirvi <[hidden email]>:

> Thanks, I have forgot all about [serialize]. Neat!
> - Jussi
>
>
> On 29.3.2012 18.45, Jonathan Guthrie wrote:
>>
>> I would use serialize and deserialize.
>>
>> local('x' = map('a' = 1, 'b' = 2);
>> then save #x->serialize to the db column
>>
>> When reading out:
>>
>> local('y' = string(field('mydata'))->deserialize);
>>
>> Untested syntax as it's from memory, so YMMV :)
>>
>>
>> On 2012-03-29, at 11:41 AM, Jussi Hirvi wrote:
>>
>>> L8.5. I never tried this before. I would like to store a map to a mysql
>>> varchar field. The saving part goes well, but I don't find a way to read the
>>> data back from the db as a map. I only get a string like: "map: (23)=(69)".
>>> I can [process] that, but I don't find a way to get data out of the
>>> [process] tag.
>>>
>>> I tried for example to capture the db data in a variable:
>>>
>>> process('[var('a') = (' + field('mymap') + ')->first]');
>>>
>>> It works to some extent - but $a ->  type is string instead of pair!
>>>
>>> Any advice?? I am slowly getting blind.
>>>
>>> - Jussi
>>
>>
>> Jono
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>



--
Mvh
Johan Sölve
____________________________________
Montania System AB
Halmstad   Stockholm
http://www.montania.se

Johan Sölve
Mobil +46 709-51 55 70
[hidden email]

Kristinebergsvägen 17, S-302 41 Halmstad, Sweden
Telefon +46 35-136800 |  Fax +46 35-136801
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

RE: Saving a map to db field

Rick Draper-2
> encode_json/decode_json is more compact and more compatible
> Johan Solve

+1 for JSON

Very best regards,

Rick



#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Saving a map to db field

Jonathan Guthrie-3
In reply to this post by Johan Solve
On 2012-03-29, at 3:42 PM, Johan Solve wrote:

> encode_json/decode_json is more compact and more compatible.

You might be right about compactness, but it doesn't preserve data types.

Jono

----------------------------
Jonathan Guthrie
[hidden email]
LassoSoft Inc.

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Saving a map to db field

Johan Solve
2012/3/29 Jonathan Guthrie <[hidden email]>:
> On 2012-03-29, at 3:42 PM, Johan Solve wrote:
>
>> encode_json/decode_json is more compact and more compatible.
>
> You might be right about compactness, but it doesn't preserve data types.

Well at least the most basic types and structures are preserved (such as maps).

--
Mvh
Johan Sölve
____________________________________
Montania System AB
Halmstad   Stockholm
http://www.montania.se

Johan Sölve
Mobil +46 709-51 55 70
[hidden email]

Kristinebergsvägen 17, S-302 41 Halmstad, Sweden
Telefon +46 35-136800 |  Fax +46 35-136801
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Saving a map to db field

Jonathan Guthrie-3
Don't know about that... strings vs integers etc :)
An integer will often become a string, and that is... suboptimal.

On 2012-03-29, at 4:49 PM, Johan Solve wrote:

> 2012/3/29 Jonathan Guthrie <[hidden email]>:
>> On 2012-03-29, at 3:42 PM, Johan Solve wrote:
>>
>>> encode_json/decode_json is more compact and more compatible.
>>
>> You might be right about compactness, but it doesn't preserve data types.
>
> Well at least the most basic types and structures are preserved (such as maps).

Jono

----------------------------
Jonathan Guthrie
[hidden email]
LassoSoft Inc.

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Saving a map to db field

Jolle Carlestam-3
30 mar 2012 kl. 06:52 skrev Jonathan Guthrie:

> Don't know about that... strings vs integers etc :)
> An integer will often become a string, and that is... suboptimal.

We use json_serialize ande json_deserialize a lot. And I both disagree and agree on Jonos claim.
Example:
var(oldmap = map('first' = 1, 'second' = '2', 3 = 'third'))
var(mystring = json_serialize($oldmap))
$mystring
br
var(newmap = json_deserialize($mystring))
$newmap
br
$newmap -> find('first') -> type
br
$newmap -> find('second') -> type

->
{"first": 1, "second": "2", 3: "third"}
map(first = 1, second = 2)
integer
string

As you can see it works fine, keeping the integers as integers as long as we only look at the values of the map. But using an integer as name doesn't seem to work. This could either be a bug in the json_deserialize code or perhaps that the json standard doesn't support integers as name params.

Anyway, for our purposes moving to and from json is really convenient and effective. We never have integers as name params in our code anyway.

HDB
Jolle
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Saving a map to db field

Jonathan Guthrie-3
Agreed, json can be very useful ...
*as long as you understand it's not the foolproof method*

The integers being deemed "name params" is an incorrect way of looking at things, it's object-centric.
However many times when you are grouping data series this will occur, and it's the reason I will store objects that have specific data types - that way you know what you're getting without having to hope it all just works :)

Serialize is bloated, agreed, but it's also taking the guesswork away, and has the advantage of working with custom data types :)


On 2012-03-29, at 8:46 PM, Jolle Carlestam wrote:

> Anyway, for our purposes moving to and from json is really convenient and effective. We never have integers as name params in our code anyway.

Jono

----------------------------
Jonathan Guthrie
[hidden email]
LassoSoft Inc.

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

RE: Saving a map to db field

Daniel Logue
If anyone is using SQL Server, Lasso's serialize + SQL Server's XML columns are great.  You can query/extract the XML straight from SQL.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Jonathan Guthrie
Sent: Thursday, March 29, 2012 5:51 PM
To: [hidden email]
Subject: Re: Saving a map to db field

Agreed, json can be very useful ...
*as long as you understand it's not the foolproof method*

The integers being deemed "name params" is an incorrect way of looking at things, it's object-centric.
However many times when you are grouping data series this will occur, and it's the reason I will store objects that have specific data types - that way you know what you're getting without having to hope it all just works :)

Serialize is bloated, agreed, but it's also taking the guesswork away, and has the advantage of working with custom data types :)


On 2012-03-29, at 8:46 PM, Jolle Carlestam wrote:

> Anyway, for our purposes moving to and from json is really convenient and effective. We never have integers as name params in our code anyway.

Jono

----------------------------
Jonathan Guthrie
[hidden email]
LassoSoft Inc.

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>