Skip to content

Commit a22955e

Browse files
fadeevJerónimo Albi
andauthored
fix(template): use slashes for key separators (ignite#2815)
* fix: use slashes for key separators * docs: prefixes Co-authored-by: Jerónimo Albi <jeronimo.albi@tendermint.com>
1 parent 7d21a07 commit a22955e

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

docs/docs/guide/03-blog/00-build-blog.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ The next step is to define the `AppendPost` keeper method.
172172

173173
Create the `x/blog/keeper/post.go` file and start thinking about the logic of the function and what you want to call the prefixes. The file will be empty for now.
174174

175-
- To implement `AppendPost` you must first understand how the key store works. You can think of a store as a key-value database where keys are lexicographically ordered. You can loop through keys and use `Get` and `Set` to retrieve and set values based on keys. To distinguish between different types of data that a module can keep in its store, you can use prefixes like `product-` or `post-`.
175+
- To implement `AppendPost` you must first understand how the key store works. You can think of a store as a key-value database where keys are lexicographically ordered. You can loop through keys and use `Get` and `Set` to retrieve and set values based on keys. To distinguish between different types of data that a module can keep in its store, you can use prefixes like `product/` or `post/`.
176176

177-
- To keep a list of posts in what is essentially a key-value store, you need to keep track of the index of the posts you insert. Since both post values and post count (index) values are kept in the store, you can use different prefixes: `Post-value-` and `Post-count-`.
177+
- To keep a list of posts in what is essentially a key-value store, you need to keep track of the index of the posts you insert. Since both post values and post count (index) values are kept in the store, you can use different prefixes: `Post/value/` and `Post/count/`.
178178

179179
Then, add these prefixes to the `x/blog/types/keys.go` file in the `const` and add a comment that describes the keys:
180180

@@ -183,8 +183,8 @@ const (
183183
// ...
184184

185185
// Keep track of the index of posts
186-
PostKey = "Post-value-"
187-
PostCountKey = "Post-count-"
186+
PostKey = "Post/value/"
187+
PostCountKey = "Post/count/"
188188
)
189189
```
190190

@@ -223,7 +223,7 @@ First, implement `GetPostCount`:
223223

224224
```go
225225
func (k Keeper) GetPostCount(ctx sdk.Context) uint64 {
226-
// Get the store using storeKey (which is "blog") and PostCountKey (which is "Post-count-")
226+
// Get the store using storeKey (which is "blog") and PostCountKey (which is "Post/count/")
227227
store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.PostCountKey))
228228

229229
// Convert the PostCountKey to bytes
@@ -246,7 +246,7 @@ Now that `GetPostCount` returns the correct number of posts in the store, implem
246246

247247
```go
248248
func (k Keeper) SetPostCount(ctx sdk.Context, count uint64) {
249-
// Get the store using storeKey (which is "blog") and PostCountKey (which is "Post-count-")
249+
// Get the store using storeKey (which is "blog") and PostCountKey (which is "Post/count/")
250250
store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(types.PostCountKey))
251251

252252
// Convert the PostCountKey to bytes
@@ -256,7 +256,7 @@ func (k Keeper) SetPostCount(ctx sdk.Context, count uint64) {
256256
bz := make([]byte, 8)
257257
binary.BigEndian.PutUint64(bz, count)
258258

259-
// Set the value of Post-count- to count
259+
// Set the value of Post/count/ to count
260260
store.Set(byteKey, bz)
261261
}
262262
```

docs/docs/guide/03-blog/01-comment-blog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ message Post {
251251

252252
The function `ignite scaffold list comment --no-message` has fetched all of the required functions for keeper.
253253

254-
Inside `x/blog/types/keys.go` file, you can see that the `comment-value` and `comment-count` keys are added.
254+
Inside `x/blog/types/keys.go` file, you can see that the `Comment/value/` and `Comment/count/` keys are added.
255255

256256
## Write data to the store
257257

ignite/templates/typed/list/stargate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ func typesKeyModify(opts *typed.Options) genny.RunFn {
251251
}
252252
content := f.String() + fmt.Sprintf(`
253253
const (
254-
%[1]vKey= "%[1]v-value-"
255-
%[1]vCountKey= "%[1]v-count-"
254+
%[1]vKey= "%[1]v/value/"
255+
%[1]vCountKey= "%[1]v/count/"
256256
)
257257
`, opts.TypeName.UpperCamel)
258258
newFile := genny.NewFileS(path, content)

ignite/templates/typed/singleton/stargate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func typesKeyModify(opts *typed.Options) genny.RunFn {
8888
}
8989
content := f.String() + fmt.Sprintf(`
9090
const (
91-
%[1]vKey= "%[1]v-value-"
91+
%[1]vKey= "%[1]v/value/"
9292
)
9393
`, opts.TypeName.UpperCamel)
9494
newFile := genny.NewFileS(path, content)

0 commit comments

Comments
 (0)