implemented get all shares
This commit is contained in:
@@ -10,5 +10,6 @@ type DB interface {
|
||||
GetShare(ctx context.Context, slug string) (*types.Share, error)
|
||||
CreateShare(ctx context.Context, share *types.Share) error
|
||||
DeleteShare(ctx context.Context, slug string) error
|
||||
GetAllShares(ctx context.Context) ([]*types.Share, error)
|
||||
Close() error
|
||||
}
|
||||
|
||||
@@ -78,6 +78,28 @@ func (db *sqlLiteDB) DeleteShare(ctx context.Context, slug string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *sqlLiteDB) GetAllShares(ctx context.Context) ([]*types.Share, error) {
|
||||
res, err := db.db.QueryContext(ctx, "SELECT slug, objKey FROM shares")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var shares []*types.Share
|
||||
|
||||
for res.Next() {
|
||||
var share types.Share
|
||||
|
||||
err = res.Scan(&share.Slug, &share.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
shares = append(shares, &share)
|
||||
}
|
||||
|
||||
return shares, nil
|
||||
}
|
||||
|
||||
func (db *sqlLiteDB) Close() error {
|
||||
return db.db.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user