Cloud Database Basics
Skygear allows users to store records to Skygear's PostgreSQL cloud database.
You can even define your own type of
Record and add customized fields to suit
Before you proceed, please make sure:
You have your Skygear container configured. Simply follows the guide at Setup Skygear if you haven't.
You have signed up as a
Userand logged in, as you have to be authenticated to perform any database operations. For guide on sign up and log in, go to User Authentication Basics.
To visualize your database with graphical presentation, you can go to the Database section in Skygear Portal and open our web data browser.
Record is the data storage unit in Skygear.
Recordmust be given a
typeis simply a
Recorddescribing the type of data this record holds.
Recordobject contains a
java.util.Maprepresenting its attributes; Keys will be mapped to database column names, and values will be stored accordingly based on the data type.
- There exist some reserved keys that cannot be used as a key for an attribute. Examples are
recordType. Please refer to Reserved Columns section for more information.
Recordcreated will be owned by the currently logged in user.
Recordobject has a unique
id(a string combination of record type and uuid is used).
Before doing any record operations, you have to understand how databases in Skygear work. You are provided with a private and a public database:
Every record in the private database is truly private, regardless of the Access Control List (ACL) set.
Records saved at the public database is set to public by default. ACL can be set per record.
The public and private database can be retrieved using:
Below are the data types Skygear supports:
There are also four other types provided by the Skygear SDK:
- Reference (relational records)
- Asset (files)
For each new record type stored in the database, a table with the same name as the record type is created. For example, if your record type is called
Note which no record of this type has been saved before, a new table called
will be created. Each row in the table corresponds to one record of type
For each record table there exists two types of columns (fields of a record), those reserved by Skygear and those user-defined. Reserved columns contain metadata of a record, such as record ID, record owner and creation time. These reserved columns are prefixed with underscore, like
It is possible to manipulate data in record tables directly. A quick way to update or delete records directly is to use our web data browser. Please note that reserved columns cannot be manipulated this way, and one should exercise with caution when modifying data directly in record tables.
Each record table contains the following reserved columns:
| Column Name | Object Attribute | Type | Description |
String | unique id of a record |
String | user id of owner of a record |
java.util.Date | creation time of a record |
String | id of user who created a record |
java.util.Date | last update time of a record |
String | id of user who last updated a record |
Learn how to get the metadata in More About Queries.