When i try to save an entity that contains with a Calendar object i get the following error.
'class java.util.GregorianCalendar' is not a registered #Subclass"
I want to be able to store a time stamp with my entity. Storing the time as a string works but id like to keep it as an object if possible.
Is there something specific i need to do to be able to store a Calendar object with objectify?
If i can not store a Calendar object, what is the best alternative for storing a timestamp with objectify(hopefully using standard java classes)?
java.util.Date is a good choice.
Related
I'm trying to find a way to save a new object if one like it doesn't already exist with a specified custom ID.
I basically need to refresh a whole bunch of data every day but each item has its own ID set somewhere else (so not a parse objectId). I therefore can't use something like the standard save function as it'll just make a new record every time.
I've thought of trying to set the objectId of an object when its first created in the DB but I can't seem to do that... (Half expected this).
I've also thought of doing the obvious - checking if an object exists using a normal query but with a few thousand objects to compare, this will be very inefficient.
Any suggestions?
Maybe there is a save function or variation where its kind of "save or create depending if an object exists with this value in this field" :)
Thank you!
PS. I'm writing this within a Cloud Job - so JavaScript
I am reading an article casting created_at to a string as it will return as an object by default. When to make request exactly? I know that the request can be used to transform one format to another. But when exactly? Any rules like when you create a data column you must use it? Things like that?
Using created_at as a string is not a best practice. Laravel Eloquent will automatically extract them from DB and cast them to Carbon instance, so you can transform it with a string (with ->format()) whenever you want.
Plus, having a Carbon object, you have access to lots of methods to handle your date, like comparison, extraction of single data (like day, month, hours...), so it doesn't make sense to cast it to a string, imho.
I need to update the current user and refetch every time the App launches so that I can grasp the most updated version of user object instead of using the one cached on the disk.
User.current()?.fetchInBackground(block: { (user, error) in
//simply using a fetchInBackground won't fetch the entire reference field store in
// the user collection. In the case of using PFQuery, we could simply include the key for
// reference field.
})
Do I have to do extra fetches for all those reference field and then update the current user's filed correspondingly?
Fetch only returns the data that is stored in your database. For a pointer, that is just a basic JSON object specifying it's a pointer, the class name, and the objectId of that object. In order to return this data, you'll instead want to use a Parse Query and include the field that you want. Include works with dot notation, so you could do something like objectAQuery.include("objectB.objectC") which will include all of the data of objectC stored as a pointer on objectB. That will not include all of objectB's data, if I'm not mistaken, though I can't say with certainty.
Finally, use query.get() to get an object with a specific objectId. This will throw an error if the object does not exist, though, so make sure you handle that appropriately. You could also use query equalTo on the objectId then call query.first(), but get would be more recommended.
I am trying to wrap my head around Bleve and I understand everything that is going on in the tutorials, videos and documentation. I however get very confused when I am using it on BoltDB and don't know how to start.
Say I have an existing BoltDB database called data.db populated with values of struct type Person
type Person struct {
ID int `json:"id"`
Name string `json:"name"`
Age int `json:"age"`
Sex string `json:"sex"`
}
How do I index this data so that I can do a search? How do I handle the indexing of data that will be stored in the database in the future?
Any help will be highly appreciated.
Bleve uses BoltDB as one of several backend stores and is separate from where you store your application data. To index your data in Bleve, simply add your Index:
index.Index(person.ID, person)
That index exists separately from your application data (whether it's in Bolt, Postgres, etc).
To retrieve your data, you'll need to construct a search request using bleve.NewSearchRequest(), then call Index.Search(). This will return a SearchResult which includes a Hits field where you can retrieve the ID for your object. You can use this to look up the object in your application data store.
Disclaimer: I am the author of BoltDB.
How you index your data depends on how you want to query for it.
If you want to query by any arbitrary fields, like {Age:15, Name:"Bob"} then BoltDB isn't an awesome fit for your problem.
BoltDB is simply a key value store with fast access to sequential keys and efficient prefix seeking. It's not really a replacement for general use databases.
You likely want something more like a document store (ie: MongoDB) or RDBMS (ie: PostgreSQL).
If you just wanted something that uses simple files and is embedded, you could also use SQlite with the Go module
If you want to search by only a single field, like ID or Name, then use that as the key.
If lookup speed doesn't matter at all, I guess you can use Bolt to just iterate over the entire db, parse the json and check the fields. But that's probably the worst approach you could take.
I need to convert a Session object to an IOrderedQueryable and came up blank. I've thought of creating a wrapper, but its not working properly. Basically, I am pulling a Linq query and would like to store it so that I don't have to pull it each time I visit. There are up to 7-10 parameters per user so it's not something that's great for caching.
I can simply cast my Session object as an IOrderedQueryable like:
(IOrderedQueryable<T>)Session["myObject"];
It seems you want to store the data returned by the linq query, if that's the case you need to make it grab the data i.e. by using .ToList() and storing that.