diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts index dfbcea11dae41540078e23fd102a837239841a12..717af1790a24f24e26dfe88986e0dac7fe1acb0d 100644 --- a/api/@ohos.data.rdb.d.ts +++ b/api/@ohos.data.rdb.d.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { AsyncCallback } from './basic'; +import {AsyncCallback, Callback} from './basic'; import { ResultSet } from './data/rdb/resultSet'; /** @@ -56,6 +56,60 @@ declare namespace rdb { function deleteRdbStore(name: string, callback: AsyncCallback): void; function deleteRdbStore(name: string): Promise; + /** + * Indicates the database synchronization mode. + * + * @since 8 + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @import N/A + * @permission N/A + */ + enum SyncMode { + /** + * Indicates the data is pushed to remote device from local device. + * + * @since 8 + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @import N/A + * @permission N/A + */ + SYNC_MODE_PUSH = 0, + + /** + * Indicates the data is pulled from remote device to local device. + * + * @since 8 + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @import N/A + * @permission N/A + */ + SYNC_MODE_PULL = 1, + } + + /** + * Describes the subscription type. + * + * @since 8 + * @Syscap SystemCapability.Data.DATA_DISTRIBUTEDDATAMGR + * @devices phone, tablet, tv, wearable, car + * @import N/A + * @permission N/A + */ + enum SubscribeType { + /** + * Subscription to remote data changes + * @since 8 + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @import N/A + * @permission N/A + */ + SUBSCRIBE_TYPE_REMOTE = 0, + } + /** * Provides methods for managing the relational database (RDB). * @@ -206,6 +260,60 @@ declare namespace rdb { */ setDistributedTables(tables: Array, callback: AsyncCallback): void; setDistributedTables(tables: Array): Promise; + + /** + * Obtain distributed table name of specified remote device according to local table name. + * When query remote device database, distributed table name is needed. + * + * @note N/A + * @since 8 + * @sysCap SystemCapability.Data.DATA_APPDATAMGR + * @param device Indicates the remote device. + * @param table Indicates the local table name. + * @return the distributed table name. + * @devices phone, tablet, tv, wearable, car + */ + obtainDistributedTableName(device: string, table: string, callback: AsyncCallback): void; + obtainDistributedTableName(device: string, table: string): Promise; + + /** + * Sync data between devices + * + * @note N/A + * @since 8 + * @sysCap SystemCapability.Data.DATA_APPDATAMGR + * @param mode Indicates the synchronization mode. The value can be PUSH, PULL. + * @param predicates Constraint synchronized data and devices. + * @param callback Indicates the callback used to send the synchronization result to the caller. + * @devices phone, tablet, tv, wearable, car + */ + sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback>): void; + sync(mode: SyncMode, predicates: RdbPredicates): Promise>; + + /** + * Registers a observer for the database. When data in the distributed database changes, + * the callback will be invoked. + * + * @note N/A + * @since 8 + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @param type Indicates the subscription type, which is defined in {@code SubscribeType}. + * @param observer Indicates the observer of data change events in the distributed database. + */ + on(event: 'dataChange', type: SubscribeType, observer: Callback>): void; + + /** + * Remove specified observer of specified type from the database. + * + * @note N/A + * @since 8 + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @param type Indicates the subscription type, which is defined in {@code SubscribeType}. + * @param observer Indicates the data change observer already registered . + */ + off(event:'dataChange', type: SubscribeType, observer: Callback>): void; } /** @@ -273,6 +381,29 @@ declare namespace rdb { */ constructor(name: string) + /** + * Specify remote devices when syncing distributed database. + * + * @note When query database, this function should not be called. + * @since 8 + * @sysCap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @param devices Indicates specified remote devices. + * @return Returns the RdbPredicates self. + */ + inDevices(devices: Array): RdbPredicates; + + /** + * Specify all remote devices which connect to local device when syncing distributed database. + * + * @note When query database, this function should not be called. + * @since 8 + * @sysCap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @return Returns the RdbPredicates self. + */ + inAllDevices(): RdbPredicates; + /** * Configures the RdbPredicates to match the field whose data type is ValueType and value is equal * to a specified value.