提交 f85e1603 编写于 作者: L ltdong

update sample code

Signed-off-by: Nltdong <donglongtao@huawei.com>
上级 6f741790
...@@ -622,7 +622,7 @@ distinct(): DataAbilityPredicates ...@@ -622,7 +622,7 @@ distinct(): DataAbilityPredicates
``` ```
let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE") let predicates = new dataAbility.DataAbilityPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").distinct("NAME") predicates.equalTo("NAME", "Rose").distinct("NAME")
let resultSet = await rdbStore.query(predicates, ["NAME"]) rdbStore.query(predicates, ["NAME"])
``` ```
......
...@@ -698,7 +698,7 @@ distinct(): RdbPredicates ...@@ -698,7 +698,7 @@ distinct(): RdbPredicates
``` ```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE") let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("NAME", "Rose").distinct("NAME") predicates.equalTo("NAME", "Rose").distinct("NAME")
let resultSet = await rdbStore.query(predicates, ["NAME"]) rdbStore.query(predicates, ["NAME"])
``` ```
......
...@@ -14,8 +14,9 @@ let predicates = new dataRdb.RdbPredicates("EMPLOYEE") ...@@ -14,8 +14,9 @@ let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
predicates.equalTo("AGE", 18) predicates.equalTo("AGE", 18)
let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) let promise = rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"])
promise.then((resultSet) => { promise.then((resultSet) => {
await console.log(TAG + "resultSet columnNames:" + resultSet.columnNames); console.log("resultSet columnNames:" + resultSet.columnNames);
await console.log(TAG + "resultSet columnCount:" + resultSet.columnCount);}) console.log("resultSet columnCount:" + resultSet.columnCount);
})
``` ```
...@@ -114,10 +115,11 @@ goTo(offset:number): boolean ...@@ -114,10 +115,11 @@ goTo(offset:number): boolean
- 示例: - 示例:
``` ```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE") let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goTo(1) resultSet.goTo(1);
resultSet.close() resultSet.close();
resultSet = null resultSet = null;
})
``` ```
...@@ -140,10 +142,11 @@ goToRow(position: number): boolean ...@@ -140,10 +142,11 @@ goToRow(position: number): boolean
- 示例: - 示例:
``` ```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE") let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToRow(1) resultSet.goToRow(1);
resultSet.close() resultSet.close();
resultSet = null resultSet = null
})
``` ```
...@@ -163,10 +166,11 @@ goToFirstRow(): boolean ...@@ -163,10 +166,11 @@ goToFirstRow(): boolean
- 示例: - 示例:
``` ```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE") let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToFirstRow() resultSet.goToFirstRow();
resultSet.close() resultSet.close();
resultSet = null; resultSet = null;
})
``` ```
...@@ -184,10 +188,11 @@ goToLastRow(): boolean ...@@ -184,10 +188,11 @@ goToLastRow(): boolean
- 示例: - 示例:
``` ```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE") let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToLastRow() resultSet.goToLastRow();
resultSet.close() resultSet.close();
resultSet = null; resultSet = null;
})
``` ```
...@@ -205,10 +210,11 @@ goToNextRow(): boolean ...@@ -205,10 +210,11 @@ goToNextRow(): boolean
- 示例: - 示例:
``` ```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE") let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToNextRow() resultSet.goToNextRow()
resultSet.close() resultSet.close()
resultSet = null; resultSet = null;
})
``` ```
...@@ -226,10 +232,11 @@ goToPreviousRow(): boolean ...@@ -226,10 +232,11 @@ goToPreviousRow(): boolean
- 示例: - 示例:
``` ```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE") let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.goToPreviousRow() resultSet.goToPreviousRow();
resultSet.close() resultSet.close();
resultSet = null resultSet = null
})
``` ```
...@@ -353,7 +360,8 @@ close(): void ...@@ -353,7 +360,8 @@ close(): void
- 示例: - 示例:
``` ```
let predicates = new dataRdb.RdbPredicates("EMPLOYEE") let predicates = new dataRdb.RdbPredicates("EMPLOYEE")
let resultSet = await rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]) rdbStore.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]).then((resultSet) => {
resultSet.close() resultSet.close();
resultSet = null resultSet = null
})
``` ```
...@@ -48,11 +48,13 @@ getStorageSync(path: string): Storage ...@@ -48,11 +48,13 @@ getStorageSync(path: string): Storage
import dataStorage from '@ohos.data.storage' import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext() (async () => {
var path = await context.getFilesDir() var context = featureAbility.getContext()
let storage = dataStorage.getStorageSync(path + '/mystore') var path = await context.getFilesDir()
storage.putSync('startup', 'auto') let storage = dataStorage.getStorageSync(path + '/mystore')
storage.flushSync() storage.putSync('startup', 'auto')
storage.flushSync()
})()
``` ```
...@@ -73,16 +75,18 @@ getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void ...@@ -73,16 +75,18 @@ getStorage(path: string, callback: AsyncCallback&lt;Storage&gt;): void
import dataStorage from '@ohos.data.storage' import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext() (async () => {
var path = await context.getFilesDir() var context = featureAbility.getContext()
dataStorage.getStorage(path + '/mystore', function (err, storage) { var path = await context.getFilesDir()
if (err) { dataStorage.getStorage(path + '/mystore', function (err, storage) {
console.info("Get the storage failed, path: " + path + '/mystore') if (err) {
return; console.info("Get the storage failed, path: " + path + '/mystore')
} return;
storage.putSync('startup', 'auto') }
storage.flushSync() storage.putSync('startup', 'auto')
}) storage.flushSync()
})
})()
``` ```
...@@ -107,15 +111,17 @@ getStorage(path: string): Promise&lt;Storage&gt; ...@@ -107,15 +111,17 @@ getStorage(path: string): Promise&lt;Storage&gt;
import dataStorage from '@ohos.data.storage' import dataStorage from '@ohos.data.storage'
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext() (async () => {
var path = await context.getFilesDir() var context = featureAbility.getContext()
let promise = dataStorage.getStorage(path + '/mystore') var path = await context.getFilesDir()
promise.then((storage) => { let promise = dataStorage.getStorage(path + '/mystore')
storage.putSync('startup', 'auto') promise.then((storage) => {
storage.flushSync() storage.putSync('startup', 'auto')
}).catch((err) => { storage.flushSync()
console.info("Get the storage failed, path: " + path + '/mystore') }).catch((err) => {
}) console.info("Get the storage failed, path: " + path + '/mystore')
})
}()
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册