ResultSet.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2022, Jan de Visser <jan@de-visser.net>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Vector.h>
  8. #include <LibSQL/Result.h>
  9. #include <LibSQL/Tuple.h>
  10. #include <LibSQL/Type.h>
  11. namespace SQL {
  12. struct ResultRow {
  13. Tuple row;
  14. Tuple sort_key;
  15. };
  16. class ResultSet : public Vector<ResultRow> {
  17. public:
  18. ALWAYS_INLINE ResultSet(SQLCommand command)
  19. : m_command(command)
  20. {
  21. }
  22. ALWAYS_INLINE ResultSet(SQLCommand command, Vector<ByteString> column_names)
  23. : m_command(command)
  24. , m_column_names(move(column_names))
  25. {
  26. }
  27. SQLCommand command() const { return m_command; }
  28. Vector<ByteString> const& column_names() const { return m_column_names; }
  29. void insert_row(Tuple const& row, Tuple const& sort_key);
  30. void limit(size_t offset, size_t limit);
  31. private:
  32. size_t binary_search(Tuple const& sort_key, size_t low, size_t high);
  33. SQLCommand m_command { SQLCommand::Unknown };
  34. Vector<ByteString> m_column_names;
  35. };
  36. }