IMetadataQuery.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\FilesMetadata;
  8. use OCP\FilesMetadata\Model\IFilesMetadata;
  9. /**
  10. * Model that help building queries with metadata and metadata indexes
  11. *
  12. * @since 28.0.0
  13. */
  14. interface IMetadataQuery {
  15. /** @since 28.0.0 */
  16. public const EXTRA = 'metadata';
  17. /**
  18. * Add metadata linked to file id to the query
  19. *
  20. * @see self::extractMetadata()
  21. * @since 28.0.0
  22. */
  23. public function retrieveMetadata(): void;
  24. /**
  25. * extract metadata from a result row
  26. *
  27. * @param array $row result row
  28. *
  29. * @return IFilesMetadata metadata
  30. * @see self::retrieveMetadata()
  31. * @since 28.0.0
  32. */
  33. public function extractMetadata(array $row): IFilesMetadata;
  34. /**
  35. * join the metadata_index table, based on a metadataKey.
  36. * This will prep the query for condition based on this specific metadataKey.
  37. * If a link to the metadataKey already exists, returns known alias.
  38. *
  39. * TODO: investigate how to support a search done on multiple values for same key (AND).
  40. *
  41. * @param string $metadataKey metadata key
  42. * @param bool $enforce limit the request only to existing metadata
  43. *
  44. * @return string generated table alias
  45. * @since 28.0.0
  46. */
  47. public function joinIndex(string $metadataKey, bool $enforce = false): string;
  48. /**
  49. * returns the name of the field for metadata key to be used in query expressions
  50. *
  51. * @param string $metadataKey metadata key
  52. *
  53. * @return string table field
  54. * @since 28.0.0
  55. */
  56. public function getMetadataKeyField(string $metadataKey): string;
  57. /**
  58. * returns the name of the field for metadata string value to be used in query expressions
  59. *
  60. * Note: this method loads lazy appconfig values.
  61. *
  62. * @param string $metadataKey metadata key
  63. *
  64. * @return string table field
  65. * @since 28.0.0
  66. */
  67. public function getMetadataValueField(string $metadataKey): string;
  68. }