diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..584c1a25a5b12c1515d5ee81249883d459dcdcf6 --- /dev/null +++ b/README.en.md @@ -0,0 +1,62 @@ +# Reading and Writing a KV Store + +### Overview + +This sample demonstrates how to use @ohos.data.distributedKVStore APIs to access a Key-Value (KV) store and add, delete, modify, and query records in it. + +### Preview + +| Home Page | Details Page | New Page | +|----------------------------------------|--------------------------------------------|-------------------------------------| +| ![](screenshots/devices/create.en.png) | ![](screenshots/devices/read_write.en.png) | ![](screenshots/devices/new.en.png) | + + +How to Use + +1. Select the data level, determine whether to encrypt the data, and touch Create. The details page is displayed. +2. Touch Add to display a window for adding KV pairs. You can customize the type, key, and value. +3. Touch Submit to add a data record to the database. (Every key must be unique). Then you can touch the × icon in the upper right corner or the mask area to exit. The data is not updated. +4. Touch Delete to delete the data record from the database. +5. Touch Edit to display the editing page. You can modify the data type and value, but cannot change the key name. +6. Touch Submit. The data in the database is updated. + +### Project Directory + +``` +├──entry/src/main/ets // Code +│ ├──constants +│ │ └──utils +│ │ └──KVStore.ets // Operations related to the KV store +│ ├──entryability +│ │ └──EntryAbility.ets +│ ├──entrybackupability +│ │ └──EntryBackupAbility.ets +│ ├──pages +│ │ ├──Index.ets // Home page +│ │ └──ReadWritePage.ets // Page for reading and writing +│ └──viewmodel +│ └──KVStoreType.ets // Database information class +└──entry/src/main/resources // Application resources +``` + +### How to Implement +1. Call createKVManager() to create a KVManager instance for database management. +2. Call getKVStore() and specify options and storeId to create and obtain a KV store of the SingleKVStore type. +3. Call put() to add a KV pair of a specified type to the database. +4. Call getEntries() to obtain all keys. +5. Call delete() to delete data of specified key from the database. + +### Permissions + +N/A + +### Dependencies + +N/A + +### Constraints + +1. The sample is only supported on Huawei phones with standard systems. +2. The HarmonyOS version must be HarmonyOS 5.0.0 Release or later. +3. The DevEco Studio version must be DevEco Studio 5.0.0 Release or later. +4. The HarmonyOS SDK version must be HarmonyOS 5.0.0 Release SDK or later. diff --git a/README.md b/README.md index 4e58e7128856af06b45c02d84f72d77acfd11749..1388b66f6f7025d57e6a5d05555b8e7771358410 100644 --- a/README.md +++ b/README.md @@ -41,11 +41,11 @@ ### 具体实现 -1. 使用createKVManager()接口,创建一个KVManager对象实例,用于管理数据库对象。(实现代码:[](entry/src/main/ets/common/utils/KVStore.ets)) -2. 使用getKVStore()接口,指定options和storeId,创建并得到SingleKVStore类型的KVStore数据库。(实现代码:[](entry/src/main/ets/common/utils/KVStore.ets)) -3. 使用put()接口,添加指定类型的键值对到数据库。(实现代码:[](entry/src/main/ets/common/utils/KVStore.ets)) -4. 使用getEntries()接口,获取所有键值。(实现代码:[](entry/src/main/ets/common/utils/KVStore.ets)) -5. 使用delete()接口,从数据库中删除指定键值的数据。(实现代码:[](entry/src/main/ets/common/utils/KVStore.ets)) +1. 使用createKVManager()接口,创建一个KVManager对象实例,用于管理数据库对象。 +2. 使用getKVStore()接口,指定options和storeId,创建并得到SingleKVStore类型的KVStore数据库。 +3. 使用put()接口,添加指定类型的键值对到数据库。 +4. 使用getEntries()接口,获取所有键值。 +5. 使用delete()接口,从数据库中删除指定键值的数据。 ### 相关权限 @@ -63,4 +63,4 @@ 3. DevEco Studio版本:DevEco Studio 5.0.0 Release及以上。 -4. HarmonyOS SDK版本:HarmonyOS 5.0.0 Release SDK及以上。 +4. HarmonyOS SDK版本:HarmonyOS 5.0.0 Release SDK及以上。 \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 8854973de23b08887f157a1d1fb0f44d7ebc4283..a9cb2bcf9e0b5d8c50355bb9897de5e9253fba20 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -134,6 +134,7 @@ struct Index { this.kvStore = undefined; this.kvStore = new KVStore(this.encrypted, this.securityLevel); setTimeout(() => { + this.pageInfos.clear(); this.pageInfos.pushPath(new NavPathInfo('readWritePage', [])); }, 200) }) diff --git a/screenshots/devices/create.en.png b/screenshots/devices/create.en.png new file mode 100644 index 0000000000000000000000000000000000000000..f9f4f9a352484ebedc73121b84da7b122dc5ccb3 Binary files /dev/null and b/screenshots/devices/create.en.png differ diff --git a/screenshots/devices/new.en.png b/screenshots/devices/new.en.png new file mode 100644 index 0000000000000000000000000000000000000000..aef114de98ed97d3de05f224b873b9db781dbd41 Binary files /dev/null and b/screenshots/devices/new.en.png differ diff --git a/screenshots/devices/read_write.en.png b/screenshots/devices/read_write.en.png new file mode 100644 index 0000000000000000000000000000000000000000..4986978f704e1012fdd1b4f15ae993f8dda02c57 Binary files /dev/null and b/screenshots/devices/read_write.en.png differ