implemented get all shares

This commit is contained in:
2022-05-14 23:25:50 +02:00
parent f31f1bbf02
commit 508e109734
4 changed files with 37 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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()
}