How to store a Json File Using Lift Mapper in MySql

116 views Asked by At

I am new to Liftweb. I want to Store a Json File in Mysql database using Lift Mapper

My Json File Like Below:-

[
{
    "name": "Root Category",
    "Id": "1",
    "dispName": "",
    "childs": [
        {
            "name": "Sub Category",
            "Id": "",
            "dispName": "",
            "childs": [
                {
                    "name": "Spec1",
                    "Id": "",
                    "dispName": "",
                    "childs": []
                }
            ]
        }
    ]
},
{
    "name": "Root Category",
    "Id": "",
    "dispName": "",
    "childs": [
        {
            "name": "Sub Category",
            "Id": "",
            "dispName": "",
            "childs": [
                {
                    "name": "Spec1",
                    "Id": "",
                    "dispName": "",
                    "childs": []
                }
            ]
        }
    ]
}
]   

Is it Possible to store a Json File in Lift Mapper .Please give me Suggestions. It will be great if some one provide any sample

Best Regards

GSY

1

There are 1 answers

0
yǝsʞǝla On

At the moment there is no good support for storing JSON in MySQL. I mean it's not going to provide capabilities MongoDB provides for example. However there are some JSON processing functions provided by community if you want. Given all that you can store it in VARCHAR. TEXT or BLOB field type as simple text. Here is a Mapper example:

import net.liftweb.mapper._
import net.liftweb.common._

class SomeDbClass extends LongKeyedMapper[SomeDbClass] with IdPK {
  def getSingleton = SomeDbClass

  // set limit of chars - can be used in `validate()`
  object quota_type extends MappedString(this, 1024)
}

object SomeDbClass extends SomeDbClass with LongKeyedMetaMapper[SomeDbClass]

For one of my projects I store JSON as a string in Postgres similarly because I just need to read and write it without having to parse it in DB and query by fields. Whenever I need efficient JSON storage with query and update support I use MongoDB with Record + ( Casbah or Rogue ).