Database
Constructor Summary
Public Constructor | ||
public |
constructor(dbID: String, container: Container): Database Creates a Skygear database. |
Member Summary
Public Members | ||
public get |
cacheResponse: boolean Indicating if query result should be cached locally |
|
public set |
cacheResponse: boolean Indicating if query result should be cached locally |
|
public get |
cacheStore: Store |
|
public |
dbID: String The database ID |
Method Summary
Public Methods | ||
public |
async deleteRecord(record: Record): Promise<Record> Delete a record from Skygear |
|
public |
async deleteRecordByID(type: String, id: String): Promise<String> Delete a record specified by the type and the ID |
|
public |
async deleteRecords(records: Record[] | QueryResult): Promise<Record[]> Delete records from Skygear |
|
public |
async deleteRecordsByID(type: String, ids: String[]): Promise<String[]> Delete records specified by the type and their IDs |
|
public |
async fetchRecordByID(recordType: String, recordID: String): Promise<Record> Fetches a single record with the specified ID. |
|
public |
async query(query: Query, cacheCallback: function(queryResult: QueryResult, isCached: boolean)): Promise<QueryResult> Fetches records that match the Query from Skygear. |
|
public |
async saveRecord(record: Record): Promise<Record> Saves a record to Skygear. |
|
public |
async saveRecords(records: Record[]): Promise<Record[]> Saves records to Skygear atomically. |
|
public |
uploadAsset(asset: Asset): Promise<Asset> Uploads asset to Skygear server. |
Public Constructors
Public Members
public get cacheStore: Store source
Public Methods
public async deleteRecord(record: Record): Promise<Record> source
Delete a record from Skygear
After deleting a record, the return one would have the property
deleted
set to true
.
Params:
Name | Type | Attribute | Description |
record | Record | the record |
public async deleteRecordByID(type: String, id: String): Promise<String> source
Delete a record specified by the type and the ID
Params:
Name | Type | Attribute | Description |
type | String | the record type |
|
id | String | the record ID |
Return:
Promise<String> | a promise of the deleted record ID |
public async deleteRecords(records: Record[] | QueryResult): Promise<Record[]> source
Delete records from Skygear
After deleting the records, the return ones would have the property
deleted
set to true
.
Params:
Name | Type | Attribute | Description |
records | Record[] | QueryResult | the records |
public async deleteRecordsByID(type: String, ids: String[]): Promise<String[]> source
Delete records specified by the type and their IDs
This method deletes records in the same type. To delete records in multiple types, try to use Database#deleteRecords
Params:
Name | Type | Attribute | Description |
type | String | the type of the records |
|
ids | String[] | the IDs of the records |
Return:
Promise<String[]> | a promise of the deleted record IDs |
public async fetchRecordByID(recordType: String, recordID: String): Promise<Record> source
Fetches a single record with the specified ID.
The fetch will be performed asynchronously and the returned promise will be resolved when the record is found.
Params:
Name | Type | Attribute | Description |
recordType | String | record Type |
|
recordID | String | record ID |
public async query(query: Query, cacheCallback: function(queryResult: QueryResult, isCached: boolean)): Promise<QueryResult> source
Fetches records that match the Query from Skygear.
Use this method to fetch records from Skygear by specifying a Query. The fetch will be performed asynchronously and the returned promise will be resolved when the operation completes.
If cacheCallback is provided, the SDK would try to fetch result of the query from local cache, before issuing query request to the server, and trigger the cacheCallback function if cached result is found.
Params:
Name | Type | Attribute | Description |
query | Query | ||
cacheCallback | function(queryResult: QueryResult, isCached: boolean) |
public async saveRecord(record: Record): Promise<Record> source
Saves a record to Skygear.
Params:
Name | Type | Attribute | Description |
record | Record | the record to save |