Change or override automatic "update" timestamp of Vapor 4 model - swift

I have a model in my Vapor app that has a timestamp that gets automatically updated to the current time whenever the model gets modified:
#Timestamp(key: "last_modification_date", on: .update, format: .unix)
var lastModificationDate: Date?
I find this feature to be incredibly useful because one can never forget to update the timestamp.
However, there is one case in the entire app where it would be really handy if I could modify the model without changing this value (or set it manually to a value other than the current time). Is this possible somehow?
So far I found nothing about this in the documentation or anywhere on the internet. Any help would be very much appreciated!

Unfortunately there's no way to workaround the timestamp logic in Fluent. If you want to modify a model without setting the update field you'll need to drop down to SQLKit or a raw query

Related

String collector/Constants in MDriven (For Time Picklists)

The goal is to create a date and time picker for a viewmodel in MDriven.
Date-wise, this is easily achieved by making set variable of date type.
When it comes to the time aspects, it seems to be a little more tricky since a time type does not exist, for obvious reasons.
(Yes, before you suggest so, I have already read How do I set Date AND time picker in MDriven? and it did not help fully.
Context:
We have tried to work our way around this by letting the user write their desired time in a column of Int-form and implementing constraints that disallows users to write something other than that of "hhmm". Whilst this worked, it is not practical and slows down the user-experience.
Ideally, we would like to have a picklist where the user gets to chose pre-made times (i.e 16:00, 16:30, 17:00 etc). This way, the format of the chosen time would never break the framework in which we want to make use of the time later on, since it is limited.
Question:
How could this be attained? Surely there is a way to create constants (like hard-coded, solely visible variables), or perhaps you could collect instances of string with a specific operator for this use?
I think you want a set of usual values to choose from. But possibly the chosen value could be changed by the user.
I would declare a class TimeValueStore. In this class I would have an attribute with only the time part set of a datetime, so 0000-00-00 16:00. I would add a admin UI to maintain these. (I can parse the DateTime back from a string with DateTime.Parse(vTimeStringValue)).
In the UI I can then have a combobox with TimeValueStore.allinstances.
When the user changes the picked value in the combo the value can be assigned to a viewmodel variable vPickedTime.
I would also have a DateTimePicker that sets a date in vPickedDate.
In a button named "Apply" I would have this expression: self.TheDateTimeFinallyChoosen:=vPickedDate.Add(vPickedTime)
This doesn't solve the pick-list problem, but take a look at the example in Derived Settable attributes in the MDriven Wiki.
Using derived settable attributes might be a good way to remove complexity from the UI controls.
https://wiki.mdriven.net/index.php/Derived_settable_attributes

Getting updated data from table

I have recently started working with UI5. In my current task, I have displayed data in table using JSONModel and by using TextField in template I am allowing user to update the data.
I have to get the updated complete table contents back in form of JSON so that I can update it back in database.
I have tried Table.getContextByIndex() and getProperty, however I am not getting updated data. Please let me know how this can be done.
For this purpose SAPUI5 provides two-way data binding. If a value is changed in the view, it is reflected in the corresponding model. Two-way data binding is the default binding mode. You can use the methods from model to get the data.
I guess I found the problem. As per below link.
Formatter functions allow one-way conversion only. This may be the reason why I am unable to see changes in model. .
Formatting Property Values

breezejs update cache with changes from server

I am using breezejs in a offline first manner, executing query’s initially against a server and stashing the entities in local storage where I query the entity manager cache.
When data changes on the server (by means of another app changing it using breeze) the client app synchronizes by just getting a new copy of the entities from the server.
This works great but I am wondering if there is a way that I can get only the changes from the server, I was thinking maybe set a revision GUID or timestamp on each record and then checking the metadata if it needs updating but I really have no idea on how to proceed.
So my question is can breeze be tweaked to allow for such a use case?
And is there maybe a beter way that I am overlooking?
I think your direction is correct .If you had a column with a TimeDate in every table e.g "LastModified" and that column would get updated on every record update. then you could add a filter to every breeze query after the first that says that that date must be later than the last time you did this "rebase" query or the initial loading. so It's not supported out of the box, but you can get it to work yourself. the guid per version will not really be a good idea, as you will have to send all these guids on every request, and then check all of them. time stamp makes more sense.

Options for Importing a Database & Displaying a Daily Tip

I am new to iOS programming and looking for advise for an iPhone app that I am creating.
I have an excel database of about 100 daily tips (which will continue to grow) that I want to import into the app, and have one tip display each day. The user will have access to the current daily tip, plus any prior tips from prior days in the database.
I would like to keep it as a closed app, so if a user feels they want to skip ahead to see new tips by changing their current date - I am not worried about the few who might do that.
From my searches so far, CoreData seems to be the way to go but I was looking for suggestions.
Any help is greatly appreciated.
I'll try to give you some advice to achieve what you want.
First of all, what do you mean with
I would like to keep it as a closed app, so if a user feels they want
to skip ahead to see new tips by changing their current date - I am
not worried about the few who might do that.
I'm not sure about its meaning.
Said this, based on my experience (someone else could give you other advice) I suggest you the following.
About your model you need to create an entity, say Tip, that could have the following attributes:
guid: an identifier that works as an identifier, the type could be a NSString
creation date: the creation date for your tip, the type is a NSDate
text to present: the text to present to the user, the type is a NSString
In addition you can also set a title, etc.
The date has two objectives.
First, it allows you to filter tips based on the current date. To filter you need to create a NSFetchRequest and set a NSPredicate. For example:
[NSPredicate perdicateWithFormat:#"creationDate <= %#", currentDate];
In addition it allows to sync with your service to download data. Based on the max date you find in the core data sql lite file, you could ask a service (if you use one) to give you the tips that are greater than that date.
The guid allows to have only one tip for that identifier (you could just use the date for that but I think is easier to have a guid, say 12345). This could be useful if you decide to download each time the whole data and you don't want to insert the same tips. In addition, you don't want to ricreate the db when you have new tips, but you would add only the new ones. So, you need an identifier that let you to verify if a tip is already there.
Finally, about your service (if you want to set up one) you could download data in JSON format. I think it's simply to set up.
If you are interested, here some links that could make your life easier:
Take a look at importing-and-displaying-large-data-sets-in-core-data in the case the data amount of downloaded data is huge. With iOS 5 new APIs are there, but the concepts you find in the post still remain valid.
A simple intro on Core Data (a question I answered in a previous post)
core-data-on-ios-5-tutorial-getting-started
If you want to know something else, let me know.
Hope it helps.

Automatically set the created and updated date with squeryl?

I remember seeing a trait that will automatically add the created and updated dates when using either lift's Record or Mapper ORMs.
The question is, is there a similar thing for Squeryl to automatically set the date/time the record was inserted and, less importantly, the last date/time it was updated?
If not, is it possible to make one?
There is no existing trait you can mix in to do it, but if you are using 0.9.5-SNAPSHOT you can create your own using Squeryl's lifecycle callbacks. Take a look at this message for more info: https://groups.google.com/forum/#!searchin/squeryl/lifecycle/squeryl/8FY7n0DN5fs/O2O8OhqVPSUJ. If you run into any trouble post a message to the group and we'll do what we can to help you out.