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 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 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 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:

NameTypeAttributeDescription
record Record

the record

Return:

Promise<Record>

a promise of the deleted record

public async deleteRecordByID(type: String, id: String): Promise<String> source

Delete a record specified by the type and the ID

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
records Record[] | QueryResult

the records

Return:

Promise<Record[]>

a promise of the deleted 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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
recordType String

record Type

recordID String

record 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 saveRecord(record: Record): Promise<Record> source

Saves a record to Skygear.

Params:

NameTypeAttributeDescription
record Record

the record to save

Return:

Promise<Record>

promise of saved record

public async saveRecords(records: Record[]): Promise<Record[]> source

Saves records to Skygear atomically.

Params:

NameTypeAttributeDescription
records Record[]

the records to save

Return:

Promise<Record[]>

promise of saved records

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

Uploads asset to Skygear server.

Params:

NameTypeAttributeDescription
asset Asset

the asset

Return:

Promise<Asset>

promise