sosyz commented on issue #1208:
URL: 
https://github.com/apache/incubator-answer/issues/1208#issuecomment-2564664695

   @LinkinStars 
   Thanks for your valuable feedback! Let me address each point:
   
   1. Regarding the status field:
   In my current design, data is restored when updating if records with the 
same group and key exist. Do you think direct deletion would be a better 
approach? Looking forward to your feedback on this design choice.
   2. About transaction support:
   I've implemented a simple transaction mechanism that leverages xorm's 
session. Here's how it works:
   ```go
   type PluginKVStorage struct {
        db             *xorm.Engine
        session        *xorm.Session
        pluginSlugName string
   }
   // ...
   func (kv * PluginKVStorage) Tx(ctx context.Context, fn func(ctx 
context.Context, kv KVOperator) error) error {
        if kv.session != nil {
                return fn(ctx, *kv)
        }
   
        session := kv.db.NewSession()
        defer session.Close()
        err := fn(ctx, KVOperator{
                session:        session,
                db:             kv.db,
                pluginSlugName: kv.pluginSlugName,
        })
        if err != nil {
                session.Rollback()
                return err
        }
        return session.Commit()
   }
   
   func (kv *PluginKVStorage) Get(ctx context.Context, key, group string) 
(string, error) {
        var data entity. KVStorage
   
        if key == "" && group == "" {
                return "", fmt.Errorf("either key or group must be provided")
        }
   
        // build query
        var query *xorm.Session
        if kv.session != nil {
                query = kv.session
        } else {
                query = kv.db.NewSession()
                defer query.Close()
        }
           // ...
   }
   ```
   Usage example:
   
   ```go
   err := kv.Tx(ctx, func(ctx context.Context, txKv KVOperator) error {
       if err := txKv.Set(ctx, "group1", "key1", "value1"); err != nil {
           return err
       }
       return txKv.Set(ctx, "group1", "key2", "value2")
   })
   ```
   
   3. About groups and range query:
   Great suggestion on groups and range query! I've implemented it in the PR.
   
   Please feel free to review and provide more feedback!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to