| securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the RDB store. |
| securityLevel | [SecurityLevel](#securitylevel) | Yes | Security level of the RDB store. |
| encrypt | boolean | No | Whether to encrypt the RDB store.<br>The value **true** means to encrypt the RDB store; the value **false** (default) means the opposite.|
| encrypt | boolean | No | Whether to encrypt the RDB store.<br>The value **true** means to encrypt the RDB store; the value **false** (default) means the opposite.|
| dataGroupId<sup>10+</sup> | string | No| Application group ID, which needs to be obtained from the AppGallery.<br>**Model restriction**: This attribute can be used only in the stage model.<br>This parameter is supported since API version 10. It specifies the **relationalStore** instance created in the sandbox directory corresponding to the **dataGroupId**. If this parameter is not specified, the **relationalStore** instance is created in the sandbox directory of the application.|
| dataGroupId<sup>10+</sup> | string | No| Application group ID, which needs to be obtained from the AppGallery.<br>**Model restriction**: This attribute can be used only in the stage model.<br>This parameter is supported since API version 10. It specifies the **relationalStore** instance created in the sandbox directory corresponding to the **dataGroupId**. If this parameter is not specified, the **relationalStore** instance is created in the sandbox directory of the application.|
# @ohos.data.UDMF (Unified Data Management Framework)
The **UDMF** module provides unified data management capabilities, including standard definition of data types, such as text and image. By calling the APIs provided by this module, applications can encapsulate a variety of data into unified data objects.
> **NOTE**
>
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
importUDMFfrom'@ohos.data.UDMF';
```
## UnifiedDataType
Enumerates the types of the [data records](#unifiedrecord) in the [unifiedData](#unifieddata) object.
| record | [UnifiedRecord](#unifiedrecord) | Yes | Data record to add. It is a **UnifiedRecord** child class object.|
**Example**
```js
lettext1=newUDMF.PlainText();
text1.textContent='this is textContent of text1';
letunifiedData=newUDMF.UnifiedData(text1);
lettext2=newUDMF.PlainText();
text2.textContent='this is textContent of text2';
unifiedData.addRecord(text2);
```
### getRecords
getRecords(): Array\<UnifiedRecord\>
Obtains all data records from this **UnifiedData** object. The data obtained is of the **UnifiedRecord** type. Before using the data, you need to use [getType](#gettype) to obtain the data type and convert the data type to a child class.
| summary | { [key: string]: number } | Yes | No | A directory type object, where **key** indicates the data type (see [UnifiedDataType](#unifieddatatype)), and the value indicates the total size (in bytes) of this type of records in the **UnifiedData** object.|
| totalSize | number | Yes | No | Total size of all the records in the **UnifiedData** object, in bytes. |
## UnifiedRecord
An abstract definition of the data content supported by the UDMF. A **UnifiedRecord** object contains one or more data records, for example, a text record, an image record, or an HTML record.
**UnifiedRecord** is an abstract parent class that does not hold specific data content. It cannot be added to a **UnifiedData** object directly. Instead, a child class with specific content, such as text and image, must be created.
### getType
getType(): string
Obtains the type of this **UnfiedRecord**. The data obtained by [getRecords](#getrecords) from the **UnifiedData** object is a **UnifiedRecord** object. You need to use this API to obtain the specific type of the record, convert the **UnifiedRecord** object to its child class, and call the child class interfaces.
Represents the text data. It is a child class of [UnifiedRecord](#unifiedrecord) and a base class of text data. You are advised to use the child class of **Text**, for example, [PlainText](#plaintext), [Hyperlink](#hyperlink), and [HTML](#html), to describe data.
| details | { [key: string]: string } | Yes | Yes | A dictionary type object, where both the key and value are of the string type and are used to describe the text content. For example, a data object with the following content can be created to describe a text file:<br>{<br>"title":"Title",<br>"content":"Content"<br>}<br> This parameter is optional. The default value is an empty dictionary object.|
**Example**
```js
lettext=newUDMF.Text();
text.details={
title:'MyTitle',
content:'this is content',
};
letunifiedData=newUDMF.UnifiedData(text);
```
## PlainText
Represents the plaintext data. It is a child class of [Text](#text) and is used to describe plaintext data.
| htmlContent | string | Yes | Yes | Content in HTML format. |
| plainContent | string | Yes | Yes | Plaintext without HTML tags. This parameter is optional. The default value is an empty string.|
**Example**
```js
lethtml=newUDMF.HTML();
html.htmlContent='<div><p>Title</p></div>';
html.plainContent='this is plainContent';
```
## File
Represents the file data. It is a child class of [UnifiedRecord](#unifiedrecord) and a base class of the data of the file type. You are advised to use the child class of **File**, for example, [Image](#image), [Video](#video), and [Folder](#folder), to describe data.
| details | { [key: string]: string } | Yes | Yes | A dictionary type object, where both the key and value are of the string type and are used to describe file information. For example, a data object with the following content can be created to describe a file:<br>{<br>"name":"File name",<br>"type":"File type"<br>}<br> This parameter is optional. The default value is an empty dictionary object.|
| uri | string | Yes | Yes | URI of the file data. |
Represents specific data types defined by OpenHarmony. It is a child class of [UnifiedRecord](#unifiedrecord) and a base class of OpenHarmony-specific data types. You are advised to use the child class of **SystemDefinedRecord**, for example, [SystemDefinedForm](#systemdefinedform), [SystemDefinedAppItem](#systemdefinedappitem), and [SystemDefinedPixelMap](#systemdefinedpixelmap), to describe OpenHarmony-specific data.
| details | { [key: string]: number \| string \| Uint8Array } | Yes | Yes | A dictionary type object, where the key is of the string type, and the value can be a number, a string, or a Uint8Array.<br/>This parameter is optional. The default value is an empty dictionary object.|
**Example**
```js
letsdr=newUDMF.SystemDefinedRecord();
letu8Array=newUint8Array([1,2,3,4,5,6,7,8,9,10]);
sdr.details={
title:'recordTitle',
version:1,
content:u8Array,
};
letunifiedData=newUDMF.UnifiedData(sdr);
```
## SystemDefinedForm
Represents the widget data. It is a child class of [SystemDefinedRecord](#systemdefinedrecord).
| appId | string | Yes | Yes | ID of the application, for which the icon is used. |
| appName | string | Yes | Yes | Name of the application, for which the icon is used. |
| appIconId | string | Yes | Yes | Image ID of the icon. |
| appLabelId | string | Yes | Yes | Label ID corresponding to the icon name. |
| bundleName | string | Yes | Yes | Bundle name corresponding to the icon.|
| abilityName | string | Yes | Yes | Application ability name corresponding to the icon.|
**Example**
```js
letappItem=newUDMF.SystemDefinedAppItem();
appItem.appId='MyAppId';
appItem.appName='MyAppName';
appItem.appIconId='MyAppIconId';
appItem.appLabelId='MyAppLabelId';
appItem.bundleName='MyBundleName';
appItem.abilityName='MyAbilityName';
letu8Array=newUint8Array([1,2,3,4,5,6,7,8,9,10]);
appItem.details={
appItemKey1:123,
appItemKey2:'appItemValue',
appItemKey3:u8Array,
};
letunifiedData=newUDMF.UnifiedData(appItem);
```
## SystemDefinedPixelMap
Represents the image data corresponding to the [PixelMap](js-apis-image.md#pixelmap7) defined by OpenHarmony. It is a child class of [SystemDefinedRecord](#systemdefinedrecord) and used to store only the binary data of **PixelMap**.
Represents the custom data type for applications only. It is a child class of [UnifiedRecord](#unifiedrecord) and a base class of custom data types of applications. Applications can extend custom data types based on this class.
Defines the data operation performed by the UDMF. It includes two optional parameters: **intention** and **key**. The two parameters have no default value, and can be left unspecified. For details, see the parameter description of the specific API.
| intention | [Intention](#intention) | Yes | Yes | No | Type of the data channel related to the data operation. |
| key | string | Yes | Yes | No | Unique identifier of a data object in the UDMF, which can be obtained from the return value of [insertData](#udmfinsertdata).<br>The key consists of **udmf:/**, **intention**, **bundleName**, and **groupId** with a (/) in between, for example, **udmf://DataHub/com.ohos.test/0123456789**.<br>**udmf:/** is fixed, **DataHub** is an enum of **intention**, **com.ohos.test** is the bundle name, and **0123456789** is a group ID randomly generated.|
| options | [Options](#options) | Yes | Configuration parameters. Only the value of **key** is required. |
| data | [UnifiedData](#unifieddata) | Yes | New data. |
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the data is updated successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
```ts
importUDMFfrom'@ohos.data.UDMF';
letplainText=newUDMF.PlainText();
plainText.textContent='hello world!';
letunifiedData=newUDMF.UnifiedData(plainText);
letoptions={
key:'udmf://DataHub/com.ohos.test/0123456789'
};
try{
UDMF.updateData(options,unifiedData,(err)=>{
if(err===undefined){
console.info('Succeeded in updating data.');
}else{
console.error(`Failed to update data. code is ${err.code},message is ${err.message} `);
}
});
}catch(e){
console.error(`Update data throws an exception. code is ${e.code},message is ${e.message} `);
| options | [Options](#options) | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in. |
| callback | AsyncCallback<Array<[UnifiedData](#unifieddata)>> | Yes | Callback invoked to return the queried data.<br>If only the **key** is specified in **options**, the data corresponding to the key is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** is returned.<br>If both **intention** and **key** are specified, the intersection of the two is returned, which is the result obtained when only **key** is specified. If there is no intersection between the specified **intention** and **key**, an error object is returned.|
**Example**
```ts
importUDMFfrom'@ohos.data.UDMF';
letoptions={
intention:UDMF.Intention.DATA_HUB
};
try{
UDMF.queryData(options,(err,data)=>{
if(err===undefined){
console.info(`Succeeded in querying data. size = ${data.length}`);
| options | [Options](#options) | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in.|
| Promise<Array<[UnifiedData](#unifieddata)>> | Promise used to return the result.<br>If only the **key** is specified in **options**, the data corresponding to the key is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** is returned.<br>If both **intention** and **key** are specified, the intersection of the two is returned, which is the result obtained when only **key** is specified. If there is no intersection between the specified **intention** and **key**, an error object is returned.|
**Example**
```ts
importUDMFfrom'@ohos.data.UDMF';
letoptions={
key:'udmf://DataHub/com.ohos.test/0123456789'
};
try{
UDMF.queryData(options).then((data)=>{
console.info(`Succeeded in querying data. size = ${data.length}`);
| options | [Options](#options) | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in. |
| callback | AsyncCallback<Array<[UnifiedData](#unifieddata)>> | Yes | Callback invoked to return the data deleted.<br>If only the **key** is specified in **options**, the data corresponding to the key deleted is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** deleted is returned.<br>If both **intention** and **key** are specified, the intersection of the two deleted is returned. If there is no intersection between the two, an error object is returned.|
**Example**
```ts
importUDMFfrom'@ohos.data.UDMF';
letoptions={
intention:UDMF.Intention.DATA_HUB
};
try{
UDMF.deleteData(options,(err,data)=>{
if(err===undefined){
console.info(`Succeeded in deleting data. size = ${data.length}`);
| options | [Options](#options) | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in.|
| Promise<Array<[UnifiedData](#unifieddata)>> | Promise used to return the data deleted.<br>If only the **key** is specified in **options**, the data corresponding to the key deleted is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** deleted is returned.<br>If both **intention** and **key** are specified, the intersection of the two deleted is returned. If there is no intersection between the two, an error object is returned.|
**Example**
```ts
importUDMFfrom'@ohos.data.UDMF';
letoptions={
key:'udmf://DataHub/com.ohos.test/0123456789'
};
try{
UDMF.deleteData(options).then((data)=>{
console.info(`Succeeded in deleting data. size = ${data.length}`);