Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
aeba9074
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
aeba9074
编写于
7月 30, 2023
作者:
葛
葛亚芳
提交者:
Gitee
7月 30, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update zh-cn/application-dev/reference/apis/js-apis-data-relationalStore.md.
Signed-off-by:
N
葛亚芳
<
geyafang@huawei.com
>
上级
237ce18f
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
37 addition
and
21 deletion
+37
-21
zh-cn/application-dev/reference/apis/js-apis-data-relationalStore.md
...cation-dev/reference/apis/js-apis-data-relationalStore.md
+37
-21
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-data-relationalStore.md
浏览文件 @
aeba9074
...
...
@@ -216,6 +216,8 @@ FA模型示例:
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
store
;
// 获取context
let
context
=
featureAbility
.
getContext
()
...
...
@@ -234,6 +236,8 @@ Stage模型示例:
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
var
store
;
class
EntryAbility
extends
UIAbility
{
onWindowStageCreate
(
windowStage
){
relationalStore
.
deleteRdbStore
(
this
.
context
,
"
RdbTest.db
"
,
function
(
err
)
{
...
...
@@ -287,6 +291,8 @@ FA模型示例:
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
store
;
// 获取context
let
context
=
featureAbility
.
getContext
();
...
...
@@ -304,6 +310,8 @@ Stage模型示例:
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
var
store
;
class
EntryAbility
extends
UIAbility
{
onWindowStageCreate
(
windowStage
){
let
promise
=
relationalStore
.
deleteRdbStore
(
this
.
context
,
"
RdbTest.db
"
);
...
...
@@ -353,6 +361,8 @@ FA模型示例:
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
store
;
// 获取context
let
context
=
featureAbility
.
getContext
()
const
STORE_CONFIG
=
{
...
...
@@ -375,6 +385,8 @@ Stage模型示例:
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
var
store
;
class
EntryAbility
extends
UIAbility
{
onWindowStageCreate
(
windowStage
){
const
STORE_CONFIG
=
{
...
...
@@ -434,6 +446,8 @@ FA模型示例:
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
var
store
;
// 获取context
let
context
=
featureAbility
.
getContext
();
const
STORE_CONFIG
=
{
...
...
@@ -455,6 +469,8 @@ Stage模型示例:
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
var
store
;
class
EntryAbility
extends
UIAbility
{
onWindowStageCreate
(
windowStage
){
const
STORE_CONFIG
=
{
...
...
@@ -2432,7 +2448,7 @@ store.query(predicates, function (err, resultSet) {
}
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -2480,7 +2496,7 @@ store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], function (err,
}
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -2530,7 +2546,7 @@ let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise
.
then
((
resultSet
)
=>
{
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -2585,7 +2601,7 @@ store.query("EMPLOYEE", predicates, function (err, resultSet) {
}
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -2639,7 +2655,7 @@ store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"], fu
}
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -2695,7 +2711,7 @@ let promise = store.query("EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALARY"
promise
.
then
((
resultSet
)
=>
{
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -2766,7 +2782,7 @@ store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME", "AGE", "SALAR
}
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -2837,7 +2853,7 @@ let promise = store.remoteQuery(deviceId, "EMPLOYEE", predicates, ["ID", "NAME",
promise
.
then
((
resultSet
)
=>
{
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -2884,7 +2900,7 @@ store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = 'sanguo
}
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -2930,7 +2946,7 @@ store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.NAME = ?", ['s
}
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -2978,7 +2994,7 @@ let promise = store.querySql("SELECT * FROM EMPLOYEE CROSS JOIN BOOK WHERE BOOK.
promise
.
then
((
resultSet
)
=>
{
console
.
info
(
`ResultSet column names:
${
resultSet
.
columnNames
}
, column count:
${
resultSet
.
columnCount
}
`
);
// resultSet是一个数据集合的游标,默认指向第-1个记录,有效的数据从0开始。
while
(
resultSet
.
goToNextRow
())
{
while
(
resultSet
.
goToNextRow
())
{
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
ID
"
));
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
NAME
"
));
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
AGE
"
));
...
...
@@ -3603,9 +3619,9 @@ setDistributedTables(tables: Array<string>, type: DistributedType, config:
**示例:**
```
js
let
config
=
new
relationalStore
.
DistributedConfig
();
config
.
autoSync
=
true
;
store
.
setDistributedTables
([
"
EMPLOYEE
"
],
relationalStore
.
DistributedType
.
DISTRIBUTED_CLOUD
,
config
,
function
(
err
)
{
store
.
setDistributedTables
([
"
EMPLOYEE
"
],
relationalStore
.
DistributedType
.
DISTRIBUTED_CLOUD
,
{
autoSync
:
true
}
,
function
(
err
)
{
if
(
err
)
{
console
.
error
(
`SetDistributedTables failed, code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
return
;
...
...
@@ -3650,9 +3666,9 @@ store.setDistributedTables(["EMPLOYEE"], relationalStore.DistributedType.DISTRIB
**示例:**
```
js
let
config
=
new
relationalStore
.
DistributedConfig
();
config
.
autoSync
=
true
;
let
promise
=
store
.
setDistributedTables
([
"
EMPLOYEE
"
],
relationalStore
.
DistributedType
.
DISTRIBUTED_CLOUD
,
config
);
let
promise
=
store
.
setDistributedTables
([
"
EMPLOYEE
"
],
relationalStore
.
DistributedType
.
DISTRIBUTED_CLOUD
,
{
autoSync
:
true
}
);
promise
.
then
(()
=>
{
console
.
info
(
`SetDistributedTables successfully.`
);
}).
catch
((
err
)
=>
{
...
...
@@ -3919,7 +3935,7 @@ cloudSync(mode: SyncMode, progress: Callback<ProgressDetails>, callback: A
**示例:**
```
js
relationalS
tore
.
cloudSync
(
relationalStore
.
SyncMode
.
SYNC_MODE_CLOUD_FIRST
,
function
(
progressDetails
)
{
s
tore
.
cloudSync
(
relationalStore
.
SyncMode
.
SYNC_MODE_CLOUD_FIRST
,
function
(
progressDetails
)
{
console
.
info
(
`Progess:
${
progressDetails
}
`
);
},
function
(
err
)
{
if
(
err
)
{
...
...
@@ -3960,7 +3976,7 @@ function progress(progressDetail) {
console
.
info
(
`progress:
${
progressDetail
}
`
);
}
relationalS
tore
.
cloudSync
(
relationalStore
.
SyncMode
.
SYNC_MODE_CLOUD_FIRST
,
progress
).
then
(()
=>
{
s
tore
.
cloudSync
(
relationalStore
.
SyncMode
.
SYNC_MODE_CLOUD_FIRST
,
progress
).
then
(()
=>
{
console
.
info
(
'
Cloud sync succeeded
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
`cloudSync failed, code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
...
...
@@ -3990,7 +4006,7 @@ cloudSync(mode: SyncMode, tables: string[], progress: Callback<ProgressDetail
```
js
const
tables
=
[
"
table1
"
,
"
table2
"
];
relationalS
tore
.
cloudSync
(
relationalStore
.
SyncMode
.
SYNC_MODE_CLOUD_FIRST
,
tables
,
function
(
progressDetails
)
{
s
tore
.
cloudSync
(
relationalStore
.
SyncMode
.
SYNC_MODE_CLOUD_FIRST
,
tables
,
function
(
progressDetails
)
{
console
.
info
(
`Progess:
${
progressDetails
}
`
);
},
function
(
err
)
{
if
(
err
)
{
...
...
@@ -4033,7 +4049,7 @@ function progress(progressDetail) {
console
.
info
(
`progress:
${
progressDetail
}
`
);
}
relationalS
tore
.
cloudSync
(
relationalStore
.
SyncMode
.
SYNC_MODE_CLOUD_FIRST
,
tables
,
progress
).
then
(()
=>
{
s
tore
.
cloudSync
(
relationalStore
.
SyncMode
.
SYNC_MODE_CLOUD_FIRST
,
tables
,
progress
).
then
(()
=>
{
console
.
info
(
'
Cloud sync succeeded
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
`cloudSync failed, code is
${
err
.
code
}
,message is
${
err
.
message
}
`
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录