(ctx context.Context, blockId string)
| 362 | } |
| 363 | |
| 364 | func DBFindTabForBlockId(ctx context.Context, blockId string) (string, error) { |
| 365 | return WithTxRtn(ctx, func(tx *TxWrap) (string, error) { |
| 366 | iterNum := 1 |
| 367 | for { |
| 368 | if iterNum > 5 { |
| 369 | return "", fmt.Errorf("too many iterations looking for tab in block parents") |
| 370 | } |
| 371 | query := ` |
| 372 | SELECT json_extract(b.data, '$.parentoref') AS parentoref |
| 373 | FROM db_block b |
| 374 | WHERE b.oid = ?;` |
| 375 | parentORef := tx.GetString(query, blockId) |
| 376 | oref, err := waveobj.ParseORef(parentORef) |
| 377 | if err != nil { |
| 378 | return "", fmt.Errorf("bad block parent oref: %v", err) |
| 379 | } |
| 380 | if oref.OType == "tab" { |
| 381 | return oref.OID, nil |
| 382 | } |
| 383 | if oref.OType == "block" { |
| 384 | blockId = oref.OID |
| 385 | iterNum++ |
| 386 | continue |
| 387 | } |
| 388 | return "", fmt.Errorf("bad parent oref type: %v", oref.OType) |
| 389 | } |
| 390 | }) |
| 391 | } |
| 392 | |
| 393 | func DBFindWorkspaceForTabId(ctx context.Context, tabId string) (string, error) { |
| 394 | return WithTxRtn(ctx, func(tx *TxWrap) (string, error) { |
no test coverage detected