1/** 2 * @file Describe the file 3 * Copyright (c) 2023 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import { CommonEventConstants } from '../CommonEventConstants'; 18import { sendBroadcast } from '@ohos/common/src/main/ets/broadcast/BroadcastHelper'; 19 20export const OPERATION_INSERT: string = 'insert'; 21 22export const OPERATION_UPDATE: string = 'update'; 23 24export const OPERATION_DELETE: string = 'delete'; 25 26export const OPERATION_UNKNOWN: string = 'unknown'; 27 28const BROAD_CAST_DELAY: number = 100; 29 30/** 31 * 发送数据库变化广播通知 32 * 33 * @param tableName 变化的表 34 * @param operation 操作:插入、更新、删除、未知 35 */ 36interface ParametersI { 37 table: string; 38 operation: string; 39} 40 41interface DataI { 42 parameters: ParametersI; 43} 44 45export function notifyProviderChange(tableName: string, operation: string) { 46 const data: DataI = { 47 parameters: { 48 table: tableName, 49 operation: operation, 50 } 51 }; 52 setTimeout(() => { 53 sendBroadcast(CommonEventConstants.DATA_CHANGED, data); 54 }, BROAD_CAST_DELAY); 55}