openharmony 鸿蒙 arkts-apis-data-relationalStore-e

2026-08-25 浏览 (1)

Enums

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

SecurityLevel

Enumerates the KV store security levels. Use the enum name rather than the enum value. You cannot change the security level of an RDB store from a higher level to a lower one.

NOTE

To perform data sync operations, the RDB store security level must be lower than or equal to that of the peer device. For details, see Access Control Mechanism in Cross-Device Sync.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
S11The RDB store security level is low. If data leakage occurs, minor impact will be caused on the database. An example would be a graph store containing non-sensitive system data such as wallpapers.
S22The RDB store security level is medium. If data leakage occurs, moderate impact will be caused on the database. An example would be a graph store containing audio and video data created by users or call logs.
S33The RDB store security level is high. If data leakage occurs, major impact will be caused on the database. An example would be a graph store containing user fitness, health, and location data.
S44The RDB store security level is critical. If data leakage occurs, severe impact will be caused on the database. An example would be a graph store containing authentication credentials and financial data.

EncryptionAlgo14+

Enumerates the encryption algorithms for the database. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
AES_256_GCM0AES_256_GCM.
AES_256_CBC1AES_256_CBC.
PLAIN_TEXT22+2No encryption is required.

HmacAlgo14+

Enumerates the HMAC algorithms for the database. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
SHA10HMAC_SHA1.
SHA2561HMAC_SHA256.
SHA5122HMAC_SHA512.

KdfAlgo14+

Enumerates the PBKDF2 algorithms for the database. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
KDF_SHA10PBKDF2_HMAC_SHA1.
KDF_SHA2561PBKDF2_HMAC_SHA256.
KDF_SHA5122PBKDF2_HMAC_SHA512.

Tokenizer17+

Enumerates tokenizers that can be used for FTS. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
NONE_TOKENIZER0No tokenizer is used.
ICU_TOKENIZER1The ICU tokenizer is used, which supports Chinese and multiple languages. If the ICU tokenizer is used, you can set the language to use, for example, zh_CN for Chinese and tr_TR for Turkish. For details about the supported languages, see ICU tokenizer. For details about the language abbreviations, see locales.
CUSTOM_TOKENIZER18+2A custom tokenizer is used. Chinese (simplified and traditional), English, and Arabic numerals are supported. Compared with ICU_TOKENIZER, CUSTOM_TOKENIZER has advantages in tokenization accuracy and resident memory usage. The self-developed tokenizer supports two modes: default tokenization mode and short word tokenization mode (short_words). You can use the cut_mode parameter to specify the mode. If no mode is specified, the default mode is used.

The table creation statement varies with the tokenizer in use.

Example:

For details about the definition of this.context in the sample code, see the application context of the stage model.

The following is an example of the table creation statement when ICU_TOKENIZER is used:

import { relationalStore } from '@kit.ArkData'; // Import a module.
import { UIAbility } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';

// In this example, Ability is used to obtain an RdbStore instance in the stage model. You can use other implementations as required.
class EntryAbility extends UIAbility {
  async onWindowStageCreate(windowStage: window.WindowStage) {
    let store: relationalStore.RdbStore|undefined = undefined;
    const STORE_CONFIG: relationalStore.StoreConfig = {
      name: "MyStore.db",
      securityLevel: relationalStore.SecurityLevel.S3,
      tokenizer: relationalStore.Tokenizer.ICU_TOKENIZER
    };
    store = await relationalStore.getRdbStore(this.context, STORE_CONFIG);

    const SQL_CREATE_TABLE = "CREATE VIRTUAL TABLE example USING fts4(name, content, tokenize=icu zh_CN)";
    if (store != undefined) {
      (store as relationalStore.RdbStore).executeSql(SQL_CREATE_TABLE, (err) => {
        if (err) {
          console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
          return;
        }
        console.info('create virtual table done.');
      });
    }
  }
}

The following is an example of the table creation statement when CUSTOM_TOKENIZER is used:

import { relationalStore } from '@kit.ArkData'; // Import a module.
import { UIAbility } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';

// In this example, Ability is used to obtain an RdbStore instance in the stage model. You can use other implementations as required.
class EntryAbility extends UIAbility {
  async onWindowStageCreate(windowStage: window.WindowStage) {
    let store: relationalStore.RdbStore|undefined = undefined;
    const STORE_CONFIG: relationalStore.StoreConfig = {
      name: "MyStore.db",
      securityLevel: relationalStore.SecurityLevel.S3,
      tokenizer: relationalStore.Tokenizer.CUSTOM_TOKENIZER
    };
    store = await relationalStore.getRdbStore(this.context, STORE_CONFIG);

    const SQL_CREATE_TABLE = "CREATE VIRTUAL TABLE example USING fts5(name, content, tokenize='customtokenizer')";
    if (store != undefined) {
      (store as relationalStore.RdbStore).executeSql(SQL_CREATE_TABLE, (err) => {
        if (err) {
          console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`);
          return;
        }
        console.info('create virtual table done.');
      });
    }
  }
}

The following is an example of the table creation statement when CUSTOM_TOKENIZER is used:

import { relationalStore } from '@kit.ArkData'; // Import a module.
import { UIAbility } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';

export default class EntryAbility extends UIAbility {
  async onWindowStageCreate(windowStage: window.WindowStage) {
    console.info('custom tokenizer example: window stage create begin.');
    let store: relationalStore.RdbStore|undefined = undefined;
    const storeConfig: relationalStore.StoreConfig = {
      name: "MyStore.db",
      securityLevel: relationalStore.SecurityLevel.S3
    };
    let customType = relationalStore.Tokenizer.CUSTOM_TOKENIZER;
    let customTypeSupported = relationalStore.isTokenizerSupported(customType);
    if (customTypeSupported) {
      storeConfig.tokenizer = customType;
    } else {
      console.info('custom tokenizer example: not support custom tokenizer.');
      return;
    }
    store = await relationalStore.getRdbStore(this.context, storeConfig);

    const sqlCreateTable =
      "CREATE VIRTUAL TABLE example USING fts5(name, content, tokenize='customtokenizer cut_mode short_words')";
    if (store != undefined) {
      (store as relationalStore.RdbStore).executeSql(sqlCreateTable, (err) => {
        if (err) {
          console.error(`custom tokenizer example: ExecuteSql failed, code is ${err.code},message is ${err.message}`);
          return;
        }
        console.info('custom tokenizer example: create virtual table done.');
      });
    }
  }
}

AssetStatus10+

Enumerates the asset statuses. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
ASSET_NORMAL1The asset is in normal status.
ASSET_INSERT2The asset is to be inserted to the cloud.
ASSET_UPDATE3The asset is to be updated to the cloud.
ASSET_DELETE4The asset is to be deleted from the cloud.
ASSET_ABNORMAL5The asset is in abnormal status.
ASSET_DOWNLOADING6The asset is being downloaded to a local device.

SyncMode

Defines the database synchronization mode. Use the enum name rather than the enum value.

NameValueDescription
SYNC_MODE_PUSH0Data is pushed from a local device to a remote device.
System capability: SystemCapability.DistributedDataManager.RelationalStore.Core
SYNC_MODE_PULL1Data is pulled from a remote device to a local device.
System capability: SystemCapability.DistributedDataManager.RelationalStore.Core
SYNC_MODE_TIME_FIRST10+4Synchronize with the data with the latest modification time.
System capability: SystemCapability.DistributedDataManager.CloudSync.Client
SYNC_MODE_NATIVE_FIRST10+5Synchronize data from a local device to the cloud.
System capability: SystemCapability.DistributedDataManager.CloudSync.Client
SYNC_MODE_CLOUD_FIRST10+6Synchronize data from the cloud to a local device.
System capability: SystemCapability.DistributedDataManager.CloudSync.Client

Origin11+

Enumerates the data sources. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.CloudSync.Client

NameValueDescription
LOCAL0Local data.
CLOUD1Cloud data.
REMOTE2Remote device data.

Field11+

Enumerates predicates used as query conditions. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.CloudSync.Client

NameValueDescription
CURSOR_FIELD'#_cursor'Field name used for cursor-based search.
ORIGIN_FIELD'#_origin'Field name used to specify the data source in cursor-based search.
DELETED_FLAG_FIELD'#_deleted_flag'Whether the dirty data (data deleted from the cloud) is cleared from the local device. It fills in the result set returned upon the cursor-based search.
The value true means the dirty data is cleared; the value false means the opposite.
DATA_STATUS_FIELD12+'#_data_status'Data status in the cursor-based search result set. The value 0 indicates normal data status; 1 indicates that data is retained after the account is logged out; 2 indicates that data is deleted from the cloud; 3 indicates that data is deleted after the account is logged out.
OWNER_FIELD'#_cloud_owner'Party who shares the data. It fills in the result set returned when the owner of the shared data is searched.
PRIVILEGE_FIELD'#_cloud_privilege'Operation permission on the shared data. It fills in the result set returned when the permission on the shared data is searched.
SHARING_RESOURCE_FIELD'#_sharing_resource_field'Resource shared. It fills in the result set returned when the shared resource is searched.

SubscribeType

Enumerates the subscription types. Use the enum name rather than the enum value.

NameValueDescription
SUBSCRIBE_TYPE_REMOTE0Subscribe to remote data changes.
System capability: SystemCapability.DistributedDataManager.RelationalStore.Core
SUBSCRIBE_TYPE_CLOUD10+1Subscribe to cloud data changes.
System capability: SystemCapability.DistributedDataManager.CloudSync.Client
SUBSCRIBE_TYPE_CLOUD_DETAILS10+2Subscribe to detailed information about cloud data changes.
System capability: SystemCapability.DistributedDataManager.CloudSync.Client
SUBSCRIBE_TYPE_LOCAL_DETAILS12+3Subscribe to detailed information about local data changes.
System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

RebuildType12+

Enumerates the RDB store rebuild types. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
NONE0The RDB store is not rebuilt.
REBUILT1The RDB store is rebuilt and creates an empty database. You need to create tables and restore data.
REPAIRED2The database is repaired and the undamaged data is restored. Currently, only the vector store supports this capability.

ChangeType10+

Enumerates data change types. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
DATA_CHANGE0Data change.
ASSET_CHANGE1Asset change.

DistributedType10+

Enumerates the distributed database table types. Use the enum name rather than the enum value.

NameValueDescription
DISTRIBUTED_DEVICE0Distributed database table synced between devices.
System capability: SystemCapability.DistributedDataManager.RelationalStore.Core
DISTRIBUTED_CLOUD1Distributed database table synced between a device and the cloud.
System capability: SystemCapability.DistributedDataManager.CloudSync.Client

ConflictResolution10+

Enumerates the resolutions used when a conflict occurs during data insertion or modification. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
ON_CONFLICT_NONE0No operation is performed.
ON_CONFLICT_ROLLBACK1Abort the SQL statement and roll back the current transaction.
ON_CONFLICT_ABORT2Abort the current SQL statement and revert any changes made by the current SQL statement. However, the changes made by the previous SQL statement in the same transaction are retained and the transaction remains active.
ON_CONFLICT_FAIL3Abort the current SQL statement. The FAIL resolution does not revert previous changes made by the failed SQL statement or end the transaction.
ON_CONFLICT_IGNORE4Skip the rows that contain constraint violations and continue to process the subsequent rows of the SQL statement.
ON_CONFLICT_REPLACE5Delete pre-existing rows that cause the constraint violation before inserting or updating the current row, and continue to execute the command normally.

Progress10+

Enumerates the stages in the device-cloud sync progress. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
SYNC_BEGIN0The device-cloud sync starts.
SYNC_IN_PROGRESS1The device-cloud sync is in progress.
SYNC_FINISH2The device-cloud sync is finished.

ProgressCode10+

Enumerates the device-cloud sync states. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
SUCCESS0The device-cloud sync is successful.
UNKNOWN_ERROR1An unknown error occurs during the device-cloud sync.
NETWORK_ERROR2A network error occurs during the device-cloud sync.
CLOUD_DISABLED3The cloud is unavailable.
LOCKED_BY_OTHERS4The device-cloud sync of another device is being performed.
The sync of the local device can be performed only when the cloud resources are available.
RECORD_LIMIT_EXCEEDED5The number of records or size of the data to be synced exceeds the maximum. The maximum value is configured on the cloud.
NO_SPACE_FOR_ASSET6The remaining cloud space is less than the size of the data to be synced.
BLOCKED_BY_NETWORK_STRATEGY12+7The device-cloud sync is blocked due to the network strategy.

TransactionType14+

Enumerates the types of transaction objects that can be created. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
DEFERRED0Deferred transaction object. When a deferred transaction object is created, automatic commit is disabled and no transaction will start. A read or write transaction starts only when the first read or write operation is performed.
IMMEDIATE1Immediate transaction object. When an immediate transaction object is created, a write transaction starts. If there is any uncommitted write transaction, the transaction object cannot be created and error 14800024 is returned.
EXCLUSIVE2Exclusive transaction object. In WAL mode, the exclusive transaction object is the same as the immediate transaction object. In other log modes, this type of transaction can prevent the database from being read by other connections during the transaction.

ColumnType18+

Enumerates the types of the column data. Use the enum name rather than the enum value.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameValueDescription
NULL0NULL.
INTEGER164-bit integer.
The column can hold 8-bit (including Boolean values), 16-bit, 32-bit, and 64-bit integers. If the 64-bit integer is greater than 2^53 or less than -2^53, use getString to convert the 64-bit integer to a string.
REAL2Floating-point number.
TEXT3String.
BLOB4Uint8Array.
ASSET5Asset.
ASSETS6Assets.
FLOAT_VECTOR7Float32Array.
UNLIMITED_INT8BigInt.

DistributedTableType23+

Enumerates the distributed table types. Use the enum name rather than the enum value. This item is a database-level configuration. If a database contains multiple distributed tables, all tables must use the same distributed table type; switching the table type or upgrade tables is not supported.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Model restriction: This API can be used only in the stage model.

NameValueDescription
DEVICE_COLLABORATION0Multi-device collaboration table. Data on each device is stored in an independent distributed table in an isolated manner instead of being written to the local table. The name of the distributed table is formed by prepending the peer device's device ID to the original table name.
SINGLE_VERSION1Single version table. Data is directly written to the local table of the peer device through the distributed data management framework.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-distributedKVStore-sys

openharmony 鸿蒙 capi-oh-preferences-h

openharmony 鸿蒙 capi-udmf-oh-udshyperlink

openharmony 鸿蒙 js-apis-data-dataSharePredicates

openharmony 鸿蒙 capi-udmf-oh-udsappitem

openharmony 鸿蒙 capi-rdb-oh-data-vbuckets

openharmony 鸿蒙 capi-rdb-oh-predicates

openharmony 鸿蒙 capi-rdb-oh-data-value

openharmony 鸿蒙 capi-preferences-oh-preferencespair

openharmony 鸿蒙 errorcode-datashare

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/bsx12f44