openharmony 鸿蒙 js-apis-data-sendableRelationalStore

2025-06-12 浏览 (1)

@ohos.data.sendableRelationalStore (Shared RDB Store)

The sendableRelationalStore module provides APIs for obtaining ValuesBucket of the sendable type from the query result set and transferring it between concurrent instances.

NOTE

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

Modules to Import

import { sendableRelationalStore } from '@kit.ArkData';

sendableRelationalStore.toSendableValuesBucket

toSendableValuesBucket(valuesBucket: NonSendableBucket): ValuesBucket

Converts a key-value (KV) pair that cannot be passed across threads into the data that can be passed across threads.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

NameTypeMandatoryDescription
valuesBucketNonSendableBucketYesData that cannot be passed across threads.

Return value

TypeDescription
ValuesBucketData that can be passed across threads.

Error codes

For details about the error codes, see Universal Error Codes and RDB Store Error Codes.

Error CodeError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.
14800000Inner error.

Example

const asset1: sendableRelationalStore.NonSendableAsset = {
  name: 'hangman',
  uri: '//path/example',
  path: '//path/example',
  createTime: 'createTime1',
  modifyTime: 'modifyTime1',
  size: 'size1',
};
const asset2: sendableRelationalStore.NonSendableAsset = {
  name: 'hangman',
  uri: '//path/example',
  path: '//path/example',
  createTime: 'createTime1',
  modifyTime: 'modifyTime1',
  size: 'size1',
}
const u8 = new Uint8Array([1, 2, 3]);
const valuesBucket: sendableRelationalStore.NonSendableBucket = {
  age: 18,
  name: "hangman",
  salary: 100.5,
  passed: true,
  data1: asset1,
  blobType: u8,
  bigValue: BigInt("15822401018187971961171"),
  data2: [asset1, asset2],
};

const sendableValuesBucket = sendableRelationalStore.toSendableValuesBucket(valuesBucket);

sendableRelationalStore.fromSendableValuesBucket

fromSendableValuesBucket(valuesBucket: ValuesBucket): NonSendableBucket

Converts a KV pair that can be passed across threads into the data that cannot be passed across threads.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

NameTypeMandatoryDescription
valuesBucketValuesBucketYesData that can be passed across threads.

Return value

TypeDescription
NonSendableBucketData that cannot be passed across threads.

Error codes

For details about the error codes, see Universal Error Codes and RDB Store Error Codes.

Error CodeError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.
14800000Inner error.

Example

const asset1: sendableRelationalStore.NonSendableAsset = {
  name: 'hangman',
  uri: '//path/example',
  path: '//path/example',
  createTime: 'createTime1',
  modifyTime: 'modifyTime1',
  size: 'size1',
};
const asset2: sendableRelationalStore.NonSendableAsset = {
  name: 'hangman',
  uri: '//path/example',
  path: '//path/example',
  createTime: 'createTime1',
  modifyTime: 'modifyTime1',
  size: 'size1',
}
const u8 = new Uint8Array([1, 2, 3]);

const sendableValuesBucket = sendableRelationalStore.toSendableValuesBucket({
  age: 18,
  name: "hangman",
  salary: 100.5,
  passed: true,
  data1: asset1,
  blobType: u8,
  bigValue: BigInt("15822401018187971961171"),
  data2: [asset1, asset2],
});
const nonSendableBucket = sendableRelationalStore.fromSendableValuesBucket(sendableValuesBucket);

sendableRelationalStore.toSendableAsset

function toSendableAsset(asset: NonSendableAsset): Asset

Converts the asset data that cannot be passed across threads into the data that can be passed across threads.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

NameTypeMandatoryDescription
assetNonSendableAssetYesAsset data that cannot be passed across threads.

Return value

TypeDescription
AssetAsset data that can be passed across threads.

For details about the error codes, see Universal Error Codes and RDB Store Error Codes.

Error CodeError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.
14800000Inner error.

Example

const asset1: sendableRelationalStore.NonSendableAsset = {
  name: 'hangman',
  uri: '//path/example',
  path: '//path/example',
  createTime: 'createTime1',
  modifyTime: 'modifyTime1',
  size: 'size1',
};
const sendableAsset = sendableRelationalStore.toSendableAsset(asset1);

sendableRelationalStore.fromSendableAsset

function fromSendableAsset(asset: Asset): NonSendableAsset

Converts the asset data that can be passed across threads into the data that cannot be passed across threads.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

Parameters

NameTypeMandatoryDescription
assetAssetYesAsset data that can be passed across threads.

Return value

TypeDescription
NonSendableAssetAsset data that cannot be passed across threads.

For details about the error codes, see Universal Error Codes and RDB Store Error Codes.

Error CodeError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.
14800000Inner error.

Example

const asset1: sendableRelationalStore.NonSendableAsset = {
  name: 'hangman',
  uri: '//path/example',
  path: '//path/example',
  createTime: 'createTime1',
  modifyTime: 'modifyTime1',
  size: 'size1',
};
const sendableAsset = sendableRelationalStore.toSendableAsset(asset1);
const normalAsset = sendableRelationalStore.fromSendableAsset(sendableAsset);

Asset

Represent information about an asset (such as a document, image, or video). Asset inherits from lang.ISendable and is used to implement cross-thread transfer of asset data. The asset data does not support Datashare APIs. Use sendableRelationalStore.toSendableAsset to create an Asset instance.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

NameTypeRead-OnlyOptionalDescription
namestringNoNoAsset name.
uristringNoNoAsset URI, which is an absolute path in the system.
pathstringNoNoApplication sandbox path of the asset.
createTimestringNoNoTime when the asset was created.
modifyTimestringNoNoTime when the asset was last modified.
sizestringNoNoSize of the asset.
statusnumberNoYesAsset status. For details, see relationalStore.AssetStatus. The default value is relationalStore.AssetStatus.ASSET_NORMAL.

Assets

type Assets = collections.Array<Asset>

Represent an array of Assets, which allows assets to be passed across threads.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

TypeDescription
collections.Array<Asset>Array of assets.

ValueType

type ValueType = null|number|string|boolean|collection.Uint8Array|Asset|Assets|collection.Float32Array|bigint

Defines the types of the value in a KV pair. The type varies with the parameter function.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

TypeDescription
nullThe value is null.
numberThe value is a number.
stringThe value is a string.
booleanThe value is true or false.
collection.Uint8ArrayThe value is a Uint8 array.
AssetThe value is an asset.
If the value type is Asset, the type in the SQL statement for creating a table must be ASSET.
AssetsThe value is an array of assets.
If the value type is Assets, the type in the SQL statement for creating a table must be ASSETS.
collection.Float32ArrayThe value is an array of 32-bit floating-point numbers.
If the value type is collection.Float32Array, the type in the SQL statement for creating a table must be floatvector(128).
bigintThe value is an integer of any length.
If the value type is bigint, the type in the SQL statement for creating a table must be UNLIMITED INT. For details, see Persisting RDB Store Data.
NOTE

The bigint type does not support value comparison and cannot be used with the following predicates: between, notBetween, greaterThanlessThan, greaterThanOrEqualTo, lessThanOrEqualTo, orderByAsc, and orderByDesc
To write a value of bigint type, use BigInt() or add n to the end of the value, for example, 'let data = BigInt(1234)' or 'let data = 1234n'.
If data of the number type is written to a bigint field, the type of the return value obtained (queried) is number but not bigint.

ValuesBucket

type ValuesBucket = collections.Map<string, ValueType>

Represents the KV pair that can be passed across threads.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

TypeDescription
collections.Map<string, ValueType>KV pair that can be passed across threads. The key must be a string, and the value is of the ValueType type.

NonSendableBucket

type NonSendableBucket = relationalStore.ValuesBucket

Represents the KV pair that cannot be passed across threads.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

TypeDescription
relationalStore.ValuesBucketKV pair that cannot be passed across threads.

NonSendableAsset

type NonSendableAsset = relationalStore.Asset

Represent the asset (such as a document, image, or video) that cannot be passed across threads.

System capability: SystemCapability.DistributedDataManager.RelationalStore.Core

TypeDescription
relationalStore.AssetAsset that cannot be passed across threads.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkData (ArkData Management)

harmony 鸿蒙Data

harmony 鸿蒙OH_Cursor

harmony 鸿蒙OH_Predicates

harmony 鸿蒙OH_Rdb_Config

harmony 鸿蒙OH_Rdb_Store

harmony 鸿蒙OH_VBucket

harmony 鸿蒙OH_VObject

harmony 鸿蒙Preferences

harmony 鸿蒙_r_d_b

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