From 0faaa511fc1aed9dbba580ce5b13e771331d0c80 Mon Sep 17 00:00:00 2001 From: wuchunbo Date: Sat, 22 Jan 2022 17:22:53 +0800 Subject: [PATCH 1/5] add distributed relational database API Signed-off-by: wuchunbo --- api/@ohos.data.rdb.d.ts | 152 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 1 deletion(-) diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts index dfbcea11da..3561593cd4 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,80 @@ 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 7 + * @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 local data changes + * @since 8 + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @import N/A + * @permission N/A + */ + SUBSCRIBE_TYPE_LOCAL = 0, + + /** + * 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 = 1, + + /** + * Subscription to both local and remote data changes + * @since 8 + * @Syscap SystemCapability.Data.DATA_APPDATAMGR + * @devices phone, tablet, tv, wearable, car + * @import N/A + * @permission N/A + */ + SUBSCRIBE_TYPE_ALL = 2, + } + /** * Provides methods for managing the relational database (RDB). * @@ -206,6 +280,59 @@ 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): string; + + /** + * 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 +400,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. -- Gitee From ee795a8ae11fdeb9727a7ab79bafbd319c7bf807 Mon Sep 17 00:00:00 2001 From: wuchunbo Date: Sat, 22 Jan 2022 17:30:53 +0800 Subject: [PATCH 2/5] add distributed relational database API Signed-off-by: wuchunbo --- api/@ohos.data.rdb.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts index 3561593cd4..520a005eae 100644 --- a/api/@ohos.data.rdb.d.ts +++ b/api/@ohos.data.rdb.d.ts @@ -80,7 +80,7 @@ declare namespace rdb { /** * Indicates the data is pulled from remote device to local device. * - * @since 7 + * @since 8 * @Syscap SystemCapability.Data.DATA_APPDATAMGR * @devices phone, tablet, tv, wearable, car * @import N/A -- Gitee From 186dfc11f1929b6b38b7719f519e6577bc5c64cf Mon Sep 17 00:00:00 2001 From: wuchunbo Date: Mon, 7 Feb 2022 16:00:46 +0800 Subject: [PATCH 3/5] change ObtainDistributedTableName Signed-off-by: wuchunbo --- api/@ohos.data.rdb.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts index 520a005eae..85528d3c90 100644 --- a/api/@ohos.data.rdb.d.ts +++ b/api/@ohos.data.rdb.d.ts @@ -293,7 +293,8 @@ declare namespace rdb { * @return the distributed table name. * @devices phone, tablet, tv, wearable, car */ - ObtainDistributedTableName(device: string, table: string): string; + ObtainDistributedTableName(device: string, table: string, callback: AsyncCallback): void; + ObtainDistributedTableName(device: string, table: string): Promise; /** * Sync data between devices -- Gitee From e80c6f13ac4610440ba4bb9d9052831feb8ef9d7 Mon Sep 17 00:00:00 2001 From: wuchunbo Date: Mon, 7 Feb 2022 18:11:35 +0800 Subject: [PATCH 4/5] fix typed error Signed-off-by: wuchunbo --- api/@ohos.data.rdb.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts index 85528d3c90..1308b5eb8b 100644 --- a/api/@ohos.data.rdb.d.ts +++ b/api/@ohos.data.rdb.d.ts @@ -293,8 +293,8 @@ declare namespace rdb { * @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; + obtainDistributedTableName(device: string, table: string, callback: AsyncCallback): void; + obtainDistributedTableName(device: string, table: string): Promise; /** * Sync data between devices -- Gitee From c08fedaf7fead334b8ecf5017c9d9a4b93ae2e01 Mon Sep 17 00:00:00 2001 From: wuchunbo Date: Wed, 9 Feb 2022 10:42:48 +0800 Subject: [PATCH 5/5] remove SUBSCRIBE_TYPE_LOCAL and SUBSCRIBE_TYPE_ALL Signed-off-by: wuchunbo --- api/@ohos.data.rdb.d.ts | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/api/@ohos.data.rdb.d.ts b/api/@ohos.data.rdb.d.ts index 1308b5eb8b..717af1790a 100644 --- a/api/@ohos.data.rdb.d.ts +++ b/api/@ohos.data.rdb.d.ts @@ -99,16 +99,6 @@ declare namespace rdb { * @permission N/A */ enum SubscribeType { - /** - * Subscription to local data changes - * @since 8 - * @Syscap SystemCapability.Data.DATA_APPDATAMGR - * @devices phone, tablet, tv, wearable, car - * @import N/A - * @permission N/A - */ - SUBSCRIBE_TYPE_LOCAL = 0, - /** * Subscription to remote data changes * @since 8 @@ -117,17 +107,7 @@ declare namespace rdb { * @import N/A * @permission N/A */ - SUBSCRIBE_TYPE_REMOTE = 1, - - /** - * Subscription to both local and remote data changes - * @since 8 - * @Syscap SystemCapability.Data.DATA_APPDATAMGR - * @devices phone, tablet, tv, wearable, car - * @import N/A - * @permission N/A - */ - SUBSCRIBE_TYPE_ALL = 2, + SUBSCRIBE_TYPE_REMOTE = 0, } /** -- Gitee