Skygear supports a lot of different data types, such as:
There are also four other types provided by Skygear SDK:
What Skygear provides
Skygear supports many-to-one (aka. parent-child) relation between records via reference.
SKYReference is a pointer to a record in database. Let's say we are going to
reference Record A in Record B, we first construct a reference of Record A
using its id.
// aID is a placeholder of Record A's id SKYReference *aRef = [SKYReference referenceWithRecordID:aID];
``swift // aID is a placeholder of Record A's id let aRef = SKYReference(recordID: aID)
Then assign this reference as a regular field of Record B: ```obj-c // bRecord is a placeholder of Record B's object bRecord[@"parent"] = aRef;
// bRecord is a placeholder of Record B's object bRecord?.setObject(aRef, forKey: "parent" as NSCopying!)
It will establish a reference from Record B to Record A.
Auto-Incrementing Sequence Fields
Make use of sequence object
Skygear reserves the
id field in the top level of all record as a primary key.
id must be unique and default to be Version 4 UUID. If you want to
auto-incrementing id for display purpose, Skygear provide a sequence for this
purpose. The sequence is guaranteed unique.
- You can omit the
noteIDon update, the value will remain unchanged.
- All the other
Notein the database will now automatically have their
- You can migrate any integer to auto-incrementing sequence.
- Our JIT schema at development will migrate the DB schema to sequence. All
Notewill be a sequence type once migrated.
Override sequence manually
- Supported by saving
- Only latitude and longitude of
Saving a location on record
See Location and Maps Programming Guide for help on getting current location.
Querying records by distance
Get all photos taken within 400 meters of some location.
distanceToLocation:fromLocation: is a Skygear function which returns distance
between a location field in a record and a specific location.
Sorting records by distance
Cont. from the example above.
Retrieving record location field distances relative to a point
Utilize transient fields.
Then we can access the distance in
completionHandler like this:
File Storage (Assets)
Uploading and associating an asset to a record
You can make use of
Asset to store file references such as images and videos on the database. An asset can only be saved with a record but not as a standalone upload.
Skygear automatically uploads the files to a server that you specify, like Amazon S3.
For example, you want to allow users to upload an image as an
image to his
SKYRecord. Once the user has selected the image to upload, you can save it by:
Asset names will never collide. i.e. you can upload multiple assets with the same asset name.
asset.name is rewritten after the asset being uploaded.
SKYAsset.url will be populated with an expiry URL after fetching /
querying the record from server.