need a different time for createdAt and UpdatedAt time
I am using autoCreatedAt and autoUpdatedAt in sails Model..
when i create a data it stores created time in both the fields (created_at and updated_at).
when i update a data it stores updated time in both fields .
i need static time for both the fields when it get created (it should be created time). when i update it should not affect the created time.
created_at : {type:'ref',columnType:'datetime',autoCreatedAt:true},
updated_at : {type:'ref',columnType:'datetime',autoCreatedAt:true},
when created both the field get stored created time.
when updated both the field get stored updated time.
As per #Salketer comment, your code should be:
created_at : {type:'ref',columnType:'datetime',autoCreatedAt:true},
updated_at : {type:'ref',columnType:'datetime',autoUpdatedAt:true},
More info at Sails Documentation
Related
I have created a new field in the TCA. This is now empty. Now I would like to fill this in with the creation year and the current UID when creating the data record or afterwards.
Do I have to do this via hooks or tasks?
As the uid of a new record is unknown until the record is saved there could not be a prefill.
Of course you could create a scheduler task to set a field with the value from the creation date (field cr_date) and uid regulary.
But a better solution would be a hook after the record creation as it would be less overhead.
On the other side: as the relevant data already is stored in every record (cr_date and uid):
do you realy need another field with the same information?
I have a timestamp with timezone column in postgressql, named created , that the data are saved in UTC.
I am using pg-promise 8.4.4 and I want to select the data, but set a different timezone for every client.
The logic is that my angular app uses the node.js endpoints as an api and I guess I can set the timezone while creating a DB connection, but that would be good just for my app.
What if another app, from another timezone, wants to hit the same node endpoint? How can they set the timezone?
So, in SQL I can do something like
set timezone to 'europe/athens';
select created from table;
But, how do I do this in pg-promise, for different clients?
I could do something like
cmsuser.generalQuery(`select firstname, created AT TIME ZONE '+02' from table WHERE AND activated = $1 ORDER BY created`, [true])
.then((resolved)=>{
res.json({success:true, activated:resolved});
})
and make the +02 part dynamic?
The cmsuser.generalQuery is
const generalQuery = (text, params) => {
const s = pgp.as.format(text, params);
return db.any(s)
}
There are two problems with this approach right now
-1- With the above query, without having the timezone part as dynamic, I get the firstname, but not the created, that is the date. No errors in the console.
-2- Setting the timezone per query is not a smart thing to do.
What can I do here?
Thank you
To add a CKRecord in a private CKRecordZone you need to make sure the zone exists already.
But does it mean that every time I need to insert a record I need to fetch all the zones and find if my zone exists using fetchAllRecordZonesWithCompletionHandler ? It wouldn't be very efficient.
What is the best strategy to adopt ?
Most of the examples I have seen show how to create a zone and add a record into it. But you are not going to create the zone every time, and you can't just assume it exists...
Code below will fail if the zone has not been created already
let customZone = CKRecordZone(zoneName: self.zoneName!)
// Create a CKRecord
let lessonRecord = CKRecord(recordType: self.recordType, zoneID: customZone.zoneID)
Thanks for your help.
To see if a specific zone exists, use CKFetchRecordZonesOperation and pass just the one record zone ID.
You only need to do this once if your code is setup properly.
Create a class that represents a record zone. This class should perform all of the CloudKit operations for a given zone. When you initialize an instance of this class for a specific zone, you can check to see if the zone exists. If not, then create the zone. Then you use that specific instance of this zone helper class each time you need to read or write data to that zone.
Of course every read and write operation needs to check error results to check for CKErrorZoneNotFound errors. Getting such an error probably means the zone was deleted from another copy of the app.
I am using offline data sync in Mobile Services and the following function only retrieves data where UpdatedAt > the largest updatedAt in the userTable:
await userTable.PullAsync(userTable.Where(a => a.UserName == userName));
The first time this function is executed, it retrieves my data correctly. The second time the function executes, whith a different username, it will only retrieve data where UpdatedAt is greater than the greatest UpdatedAt datetime that is already present in my SQLite db. If I change an UpdatedAt field in the backend (by setting it to DateTime.Now), this record is retrieved. Is this by design or am I missing something?
For anybody else having issues with this: I have started another thread here where you will find the complete answer
Basically what it comes down to is this:
This will retrieve all records from the backend where username is donna:
await itemTable.PullAsync(itemTable.Where(a => a.UserName == "donna"));
This will retrieve all records where username is "donna" the first time, and after that only updated records. (incremental)
await itemTable.PullAsync("itemtabledonna", itemTable.Where(a => a.UserName == "donna"));
The first parameter is the queryKey. This is used to track your requests to the backend. A very important thing to know is that there is a restriction on this queryKey:
^[a-zA-Z][a-zA-Z0-9]{0,24}$
Meaning: alphanumeric characters, max 25 characters long. So no hyphens either (at the time of this writing). If your queryKey does not match this regex, no recrods will be returned. There is currently no exception thrown and no documentation on this.
PullAsync() is supposed to use an incremental sync (getting only records what have a newer date than the last record it retrieved) when you pass in a query key. If not, it should execute your query and pull down all matching records.
It sounds like a bug is occurring if you are getting that behavior without passing in a query key.
Also, in the incremental sync case, it is not the latest updated at in the SQLite DB but a cached version from the last time PullAsync() was ran (that was cached under the given query key)
Your updatedAt column also by default will have a trigger that causes its timestamp to update whenever the row is modified, so you shouldn't have to take any additional actions when using incremental sync.
If the above is not what you are seeing, I recommend submitting a github bug against azure-mobile-services so it can be reviewed.
I want to retrieve particular values from database using Id..
Orgvasplans
Id
vasplanId
orgId
createdDate
vasplans
Id
Name
Amount
Validity
The "vasplans" table values are already stored in database.. when I click button, it is automatically taken value from vasplans table and store into orgvasplans table. Also created date will store..
In view, it will retrieve the values from orgvasplans table... But I have problem with vasplanId. can anyone please check and tell me?