• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 data_rdb from '@ohos.data.relationalStore';
18
19/**
20 * 判断ValuesBucket中是否包含某Key的值
21 *
22 * @param values 待检查的ValuesBucket
23 * @param key 待检测的key
24 */
25export function isContainsKey(values: data_rdb.ValuesBucket, key: string): boolean {
26  if (values === null || values === undefined) {
27    return false;
28  }
29  if (key === null || key === undefined) {
30    return false;
31  }
32  return values[key] !== null && values[key] !== undefined;
33}
34
35/**
36 * 判断ValuesBucket中是否包含一组Key中的某Key的值
37 *
38 * @param values 待检查的ValuesBucket
39 * @param key 待检测的一组key
40 */
41export function isContainsOneOfKeys(values: data_rdb.ValuesBucket, keys: Array<string>): boolean {
42  if (values === null || values === undefined) {
43    return false;
44  }
45  if (keys === null || keys === undefined || keys.length === 0) {
46    return false;
47  }
48  for (let key of keys) {
49    if (isContainsKey(values, key)) {
50      return true;
51    }
52  }
53  return false;
54}
55
56/**
57 * 判断ValuesBucket中是否包含一组Key中所有Key的值
58 *
59 * @param values 待检查的ValuesBucket
60 * @param key 待检测的一组key
61 */
62export function isContainsAllKeys(values: data_rdb.ValuesBucket, keys: Array<string>): boolean {
63  if (values === null || values === undefined) {
64    return false;
65  }
66  if (keys === null || keys === undefined || keys.length === 0) {
67    return false;
68  }
69  for (let key of keys) {
70    if (!isContainsKey(values, key)) {
71      return false;
72    }
73  }
74  return true;
75}