Home Reference Source
public class | source

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 del(record: Record | Record[] | QueryResult): Promise<Record>

Same as Database#delete.

public

async delete(_records: Record | Record[] | QueryResult): Promise

Deletes a record or records to Skygear.

public

async getRecordByID(id: String): Promise<Record>

Fetches a single record with the specified id from Skygear.

public

async query(query: Query, cacheCallback: function(queryResult: QueryResult, isCached: boolean)): Promise<QueryResult>

Fetches records that match the Query from Skygear.

public

async save(_records: Record | Record[], options: Object): Promise<Record>

Saves a record or records to Skygear.

public

uploadAsset(asset: Asset): Promise<Asset>

Uploads asset to Skygear server.

Public Constructors

public constructor(dbID: String, container: Container): Database source

Creates a Skygear database.

Params:

NameTypeAttributeDescription
dbID String

database ID

container Container

Skygear Container

Return:

Database

Public Members

public get cacheResponse: boolean source

Indicating if query result should be cached locally

public set cacheResponse: boolean source

Indicating if query result should be cached locally

public get cacheStore: Store source

public dbID: String source

The database ID

Public Methods

public async del(record: Record | Record[] | QueryResult): Promise<Record> source

Same as Database#delete.

Params:

NameTypeAttributeDescription
record Record | Record[] | QueryResult

the record(s) to delete

Return:

Promise<Record>

promise with the delete result

See:

public async delete(_records: Record | Record[] | QueryResult): Promise source

Deletes a record or records to Skygear.

Use this method to delete a record or records to Skygear. The delete will be performed asynchronously and the returned promise will be resolved when the operation completes.

Params:

NameTypeAttributeDescription
_records Record | Record[] | QueryResult

the records to delete

Return:

Promise

promise

public async getRecordByID(id: String): Promise<Record> source

Fetches a single record with the specified id from Skygear.

Use this method to fetch a single record from Skygear by specifying a record ID in the format of type/id. The fetch will be performed asynchronously and the returned promise will be resolved when the operation completes.

Params:

NameTypeAttributeDescription
id String

record ID with format type/id

Return:

Promise<Record>

promise with the fetched Record

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:

NameTypeAttributeDescription
query Query
cacheCallback function(queryResult: QueryResult, isCached: boolean)

Return:

Promise<QueryResult>

promise with the QueryResult

public async save(_records: Record | Record[], options: Object): Promise<Record> source

Saves a record or records to Skygear.

Use this method to save a record or records to Skygear. The save will be performed asynchronously and the returned promise will be resolved when the operation completes.

New record will be created in the database while existing record will be modified.

options.atomic can be set to true, which makes the operation either success or failure, but not partially success.

Params:

NameTypeAttributeDescription
_records Record | Record[]

the record(s) to save

options Object
  • optional
  • default: {}

options - options for saving the records

options.atomic Boolean
  • optional

true if the save request should be atomic

Return:

Promise<Record>

promise with saved records

public uploadAsset(asset: Asset): Promise<Asset> source

Uploads asset to Skygear server.

Params:

NameTypeAttributeDescription
asset Asset

the asset

Return:

Promise<Asset>

promise