FatFractal customer forums



Author Topic: Auto-detect when to Create, Update, and Delete  (Read 1571 times)

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Auto-detect when to Create, Update, and Delete
« on: January 23, 2014, 05:28:55 PM »
My current design is to load up a bunch of objects from the back end, let the user create, update & delete to their heart's content, then at the end when everything is just as they want it, let them push a button to publish it all back to the server.  Looking at the client-side SDK I see three ways to accomplish this:
  • Write my own code to decipher which objects should be created, updated, and deleted
  • Somehow design the back-end to keep all the relevant objects in a single array
  • Use some cool function I haven't found to synchronize all that for me
My question is: does #3 exist?  This is using the javascript SDK.

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #1 on: January 23, 2014, 05:42:40 PM »
Oh - and I should add that this should happen atomically.  I haven't yet discovered transaction capabilities in FatFractal, so any pointers about that would be appreciated.

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #2 on: January 24, 2014, 09:22:18 PM »
... thinking ....

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #3 on: January 28, 2014, 10:53:18 AM »
OK

Right now there is no way to do precisely what you are looking for

I think the solution is
(1) Yes mark objects dirty as required in your front-end
(2) Write a server extension to which you can send your list of things to be done. (You should wrap the array in an object)
eg you would POST something like this
{
  actions:[
    {action:'CREATE',data:{......}},
    {action:'CREATE',data:{......}},
    {action:'UPDATE',data:{......}},
    {action:'DELETE',data:{......}}
  ]
}
(3) We add transactional support. (This is something I've been postponing until someone asked for it; it is a surprisingly uncommon requirement! but I designed it a while back)


Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #4 on: January 28, 2014, 02:42:47 PM »
Ok, I will proceed with that approach, and wrap it with transaction calls once they exist.  Thank you!  :)  I too am surprised that I'm the first one to bring it up ... it seems like a pretty basic concern when dealing with data storage.

Out of curiosity, do you recommend sending all the actions in one server call (rather than executing each CRUD operation from the client) for efficiency's sake, or also because transactions will only be be a server-side feature?

And finally: why wrap the "actions" array in an object?  I'm coming from the Java world where an array is an object - should I take care not to make that assumption when dealing with FatFractal?

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #5 on: January 28, 2014, 03:50:15 PM »
Transactions will be server-side-only feature. The alternative is too horrific to contemplate (I am thinking WS DeathStar)

As for wrapping in an object - this is purely a limitation of our client SDKs right now in the postObjToExtension method. You can POST direct if you like, all you need to do is supply the auth headers (see this answer https://forum.fatfractal.com/forum/index.php?topic=16.msg53#msg53 which is to an iOS question but same thing applies in all of the client SDKs)



Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #6 on: January 28, 2014, 03:53:08 PM »
Ok, thanks for the help!

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #7 on: January 29, 2014, 10:03:16 PM »
While working on this, I find myself in a situation where the "actions" I send to the server can look like this:
[
    {name: "C"},
    {name: "P", child: <reference to C>}
]

My first guess is that on the server side it will look like this, with 2 copies of C, since I'm assuming it uses straightforward JSON:
[
    {name: "C"},
    {name: "P", child: {name: "C"}}
]

Is that correct, or does FatFractal do some fancy (de)serialization to reproduce my object graph?  If it is correct, I need to rethink some things.  *sigh*

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #8 on: January 30, 2014, 09:54:55 AM »
Or - better question - how do I debug server-side code?

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #9 on: January 30, 2014, 07:06:49 PM »
Eric,

With regards to debugging server-side code, I'd strongly recommend running an engine locally and liberal use of ff.logger

We've had a REPL in the feature backlog for a while but haven't progressed it to release

With regards to your question about serialization - well ... in this case where you're trying to send a whole bunch of things to be created / updated / deleted at the same time, it's kind of up to you how you go about it. If you want to leverage FatFractal's built-in serialization then you can do that also. What is your client-side (iOS / Android / HTML5) ?

- Gary

PS Here's the logger interface in server-side FatFractal.js

Code: [Select]
/**
 * Allows server-side code to log messages to the application's log with different severities (TRACE, INFO, WARN, ERROR).
 * <br>*** Does not increase your server-side API call count (unless you are LoggingToDatabase) ***
 * @type {{trace: Function, info: Function, warn: Function, error: Function, forceInfo: Function, forceWarn: Function}}
 */
var logger = {
    /** @param {String} msg */
    trace:  function(msg) {if (typeof msg != 'string') throw new Error("Parameter must be a string"); else FF_JS_API.logger.trace(msg);},
    /** @param {String} msg */
    info:   function(msg) {if (typeof msg != 'string') throw new Error("Parameter must be a string"); else FF_JS_API.logger.info(msg);},
    /** @param {String} msg */
    warn:   function(msg) {if (typeof msg != 'string') throw new Error("Parameter must be a string"); else FF_JS_API.logger.warn(msg);},
    /** @param {String} msg */
    error:  function(msg) {if (typeof msg != 'string') throw new Error("Parameter must be a string"); else FF_JS_API.logger.error(msg);},
    /** @param {String} msg */
    forceInfo:   function(msg) {if (typeof msg != 'string') throw new Error("Parameter must be a string"); else FF_JS_API.logger.forceInfo(msg);},
    /** @param {String} msg */
    forceWarn:   function(msg) {if (typeof msg != 'string') throw new Error("Parameter must be a string"); else FF_JS_API.logger.forceWarn(msg);}
};
exports.logger = logger;

Eric

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #10 on: January 30, 2014, 07:27:06 PM »
Thank you for the response.  I did not notice the logger in the docs - though I see it now!  (And thanks for its API, because I still did not notice that in the docs.)

I will use that to answer my previous question, but for the record and since you asked, my client side is JavaScript, and I was asking about the serialization employed by postObjToExtension().  If by "it's up to me how I go about it" you mean I'm free to write my own serialization code ... I think I'll pass.   :P

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #11 on: January 30, 2014, 07:31:28 PM »
Ah well the beautiful thing about Javascript is of course that serialization to JSON is built-in, so for simple objects (no references etc) then all you need to to is call JSON.stringify(obj)

If you want to deal with fatfractal references then I'd suggest modify your copy of FatFractal.js so that you can get a handle to this function:
Code: [Select]
    var m_transformReferencesForPersistence = function(obj) {


gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #12 on: January 30, 2014, 07:37:33 PM »
PS you can actually get a handle to our serialization methods in the iOS and Android SDKs also.

porter

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Auto-detect when to Create, Update, and Delete
« Reply #13 on: January 31, 2014, 10:37:11 PM »
I'll +1 the OP's request.  Something similar to Django's get_or_create(), or a way to enforce uniqueness of a created item when calling createObjAtUri() in the JS SDK, would be great.

 

Copyright © FatFractal customer forums