| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package memory |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "context" |
||
| 5 | "errors" |
||
| 6 | |||
| 7 | "github.com/Permify/permify/internal/storage" |
||
| 8 | "github.com/Permify/permify/internal/storage/memory/constants" |
||
| 9 | |||
| 10 | db "github.com/Permify/permify/pkg/database/memory" |
||
| 11 | base "github.com/Permify/permify/pkg/pb/base/v1" |
||
| 12 | ) |
||
| 13 | |||
| 14 | // BundleReader - |
||
| 15 | type BundleReader struct { |
||
| 16 | database *db.Memory |
||
| 17 | } |
||
| 18 | |||
| 19 | func NewBundleReader(database *db.Memory) *BundleReader { |
||
| 20 | return &BundleReader{ |
||
| 21 | database: database, |
||
| 22 | } |
||
| 23 | } |
||
| 24 | |||
| 25 | func (b *BundleReader) Read(ctx context.Context, tenantID, name string) (bundle *base.DataBundle, err error) { |
||
| 26 | txn := b.database.DB.Txn(false) |
||
| 27 | defer txn.Abort() |
||
| 28 | var raw interface{} |
||
| 29 | raw, err = txn.First(constants.BundlesTable, "id", tenantID, name) |
||
| 30 | if err != nil { |
||
| 31 | return bundle, errors.New(base.ErrorCode_ERROR_CODE_EXECUTION.String()) |
||
| 32 | } |
||
| 33 | |||
| 34 | bun, ok := raw.(storage.Bundle) |
||
| 35 | if ok { |
||
| 36 | return bun.DataBundle, err |
||
| 37 | } |
||
| 38 | |||
| 39 | return nil, errors.New(base.ErrorCode_ERROR_CODE_BUNDLE_NOT_FOUND.String()) |
||
| 40 | } |
||
| 41 |