terça-feira, 30 de julho de 2013

Delphi with jQueryMobile - Store User settings JSON object in DB

POST #021 =======================================================================
The end-result of this mini-video was demonstrate the aproach JSON based-data or key-per-column. The idea is store UI settings JSON object into Sqlite database. Once stored, I’ll retrieve these preferences when user returns to the web app and set the UI as it was when they last left it at later time. One obvious drawback of this approach is that it makes it VERY slow to find things, but it's fine for small structure of data you don't need to search by.

I'm using meta columns which stores data about the user in JSON format. For example, "roles" object is stored as TEXT in Sqlite database column, and extracted directly as such from DB. You just need to decode JSON string as a JSON object. For instance, it is just one line of javascript. I'm using the stringify method to convert the JS object into a string, store it in the Sqlite database and then pull it back and use the reverse parse method to give me the javascript object back.

Maybe this is neither the best aproach to store UI user preferences nor design-wise or performance-wise, but I believe that it often makes sense to organize small trunk of data and store it in json object in database. That's all.




Tags: smart phones with delphi; Delphi mORMot UI Settings; Delphi jquery mobile; Delphi REST server;

Warleyalex from Sete Lagoas-MG, Brazil