prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Function to order table by set of columns
  **Problem**
  <!-- Please provide a clear and concise description of the problem that this feature request is designed to solve.-->
  
  We should be able to get the records of a table in an ordering by any set of its columns.  The records should be paginated.
  
  **Proposed solution**
  <!-- A clear and concise description of your proposed solution or feature. -->
  
  We need a function at the data layer (i.e., in the `db` library) that performs this query.
  
  **Additional context**
  <!-- Add any other context or screenshots about the feature request here.-->
  
  The interesting bit will be figuring out how to paginate the results, but without having to reperform the (costly) ordering query each time.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `db/records.py`
  Content:
  ```
  1 from sqlalchemy import delete, select
  2 from sqlalchemy.inspection import inspect
  3 
  4 
  5 def _get_primary_key_column(table):
  6     primary_key_list = list(inspect(table).primary_key)
  7     # We do not support getting by composite primary keys
  8     assert len(primary_key_list) == 1
  9     return primary_key_list[0]
  10 
  11 
  12 def get_record(table, engine, id_value):
  13     primary_key_column = _get_primary_key_column(table)
  14     query = select(table).where(primary_key_column == id_value)
  15     with engine.begin() as conn:
  16         result = conn.execute(query).fetchall()
  17         assert len(result) <= 1
  18         return result[0] if result else None
  19 
  20 
  21 def get_records(table, engine, limit=None, offset=None):
  22     query = select(table).limit(limit).offset(offset)
  23     with engine.begin() as conn:
  24         return conn.execute(query).fetchall()
  25 
  26 
  27 def create_record_or_records(table, engine, record_data):
  28     """
  29     record_data can be a dictionary, tuple, or list of dictionaries or tuples.
  30     if record_data is a list, it creates multiple records.
  31     """
  32     id_value = None
  33     with engine.begin() as connection:
  34         result = connection.execute(table.insert(), record_data)
  35         # If there was only a single record created, return the record.
  36         if result.rowcount == 1:
  37             # We need to manually commit insertion so that we can retrieve the record.
  38             connection.commit()
  39             id_value = result.inserted_primary_key[0]
  40             if id_value is not None:
  41                 return get_record(table, engine, id_value)
  42     # Do not return any records if multiple rows were added.
  43     return None
  44 
  45 
  46 def update_record(table, engine, id_value, record_data):
  47     primary_key_column = _get_primary_key_column(table)
  48     with engine.begin() as connection:
  49         connection.execute(
  50             table.update().where(primary_key_column == id_value).values(record_data)
  51         )
  52     return get_record(table, engine, id_value)
  53 
  54 
  55 def delete_record(table, engine, id_value):
  56     primary_key_column = _get_primary_key_column(table)
  57     query = delete(table).where(primary_key_column == id_value)
  58     with engine.begin() as conn:
  59         return conn.execute(query)
  60
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/db/records.py b/db/records.py
  --- a/db/records.py
  +++ b/db/records.py
  @@ -18,8 +18,20 @@
           return result[0] if result else None
   
   
  -def get_records(table, engine, limit=None, offset=None):
  -    query = select(table).limit(limit).offset(offset)
  +def get_records(table, engine, limit=None, offset=None, order_by=[]):
  +    """
  +    Returns records from a table.
  +
  +    Args:
  +        table:    SQLAlchemy table object
  +        engine:   SQLAlchemy engine object
  +        limit:    int, gives number of rows to return
  +        offset:   int, gives number of rows to skip
  +        order_by: list of SQLAlchemy ColumnElements to order by.  Should
  +                  usually be either a list of string column names, or a
  +                  list of columns from the given table.
  +    """
  +    query = select(table).order_by(*order_by).limit(limit).offset(offset)
       with engine.begin() as conn:
           return conn.execute(query).fetchall()
  
verification_info: {"golden_diff": "diff --git a/db/records.py b/db/records.py\n--- a/db/records.py\n+++ b/db/records.py\n@@ -18,8 +18,20 @@\n         return result[0] if result else None\n \n \n-def get_records(table, engine, limit=None, offset=None):\n-    query = select(table).limit(limit).offset(offset)\n+def get_records(table, engine, limit=None, offset=None, order_by=[]):\n+    \"\"\"\n+    Returns records from a table.\n+\n+    Args:\n+        table:    SQLAlchemy table object\n+        engine:   SQLAlchemy engine object\n+        limit:    int, gives number of rows to return\n+        offset:   int, gives number of rows to skip\n+        order_by: list of SQLAlchemy ColumnElements to order by.  Should\n+                  usually be either a list of string column names, or a\n+                  list of columns from the given table.\n+    \"\"\"\n+    query = select(table).order_by(*order_by).limit(limit).offset(offset)\n     with engine.begin() as conn:\n         return conn.execute(query).fetchall()\n", "issue": "Function to order table by set of columns\n**Problem**\r\n<!-- Please provide a clear and concise description of the problem that this feature request is designed to solve.-->\r\n\r\nWe should be able to get the records of a table in an ordering by any set of its columns.  The records should be paginated.\r\n\r\n**Proposed solution**\r\n<!-- A clear and concise description of your proposed solution or feature. -->\r\n\r\nWe need a function at the data layer (i.e., in the `db` library) that performs this query.\r\n\r\n**Additional context**\r\n<!-- Add any other context or screenshots about the feature request here.-->\r\n\r\nThe interesting bit will be figuring out how to paginate the results, but without having to reperform the (costly) ordering query each time.\n", "before_files": [{"content": "from sqlalchemy import delete, select\nfrom sqlalchemy.inspection import inspect\n\n\ndef _get_primary_key_column(table):\n    primary_key_list = list(inspect(table).primary_key)\n    # We do not support getting by composite primary keys\n    assert len(primary_key_list) == 1\n    return primary_key_list[0]\n\n\ndef get_record(table, engine, id_value):\n    primary_key_column = _get_primary_key_column(table)\n    query = select(table).where(primary_key_column == id_value)\n    with engine.begin() as conn:\n        result = conn.execute(query).fetchall()\n        assert len(result) <= 1\n        return result[0] if result else None\n\n\ndef get_records(table, engine, limit=None, offset=None):\n    query = select(table).limit(limit).offset(offset)\n    with engine.begin() as conn:\n        return conn.execute(query).fetchall()\n\n\ndef create_record_or_records(table, engine, record_data):\n    \"\"\"\n    record_data can be a dictionary, tuple, or list of dictionaries or tuples.\n    if record_data is a list, it creates multiple records.\n    \"\"\"\n    id_value = None\n    with engine.begin() as connection:\n        result = connection.execute(table.insert(), record_data)\n        # If there was only a single record created, return the record.\n        if result.rowcount == 1:\n            # We need to manually commit insertion so that we can retrieve the record.\n            connection.commit()\n            id_value = result.inserted_primary_key[0]\n            if id_value is not None:\n                return get_record(table, engine, id_value)\n    # Do not return any records if multiple rows were added.\n    return None\n\n\ndef update_record(table, engine, id_value, record_data):\n    primary_key_column = _get_primary_key_column(table)\n    with engine.begin() as connection:\n        connection.execute(\n            table.update().where(primary_key_column == id_value).values(record_data)\n        )\n    return get_record(table, engine, id_value)\n\n\ndef delete_record(table, engine, id_value):\n    primary_key_column = _get_primary_key_column(table)\n    query = delete(table).where(primary_key_column == id_value)\n    with engine.begin() as conn:\n        return conn.execute(query)\n", "path": "db/records.py"}], "after_files": [{"content": "from sqlalchemy import delete, select\nfrom sqlalchemy.inspection import inspect\n\n\ndef _get_primary_key_column(table):\n    primary_key_list = list(inspect(table).primary_key)\n    # We do not support getting by composite primary keys\n    assert len(primary_key_list) == 1\n    return primary_key_list[0]\n\n\ndef get_record(table, engine, id_value):\n    primary_key_column = _get_primary_key_column(table)\n    query = select(table).where(primary_key_column == id_value)\n    with engine.begin() as conn:\n        result = conn.execute(query).fetchall()\n        assert len(result) <= 1\n        return result[0] if result else None\n\n\ndef get_records(table, engine, limit=None, offset=None, order_by=[]):\n    \"\"\"\n    Returns records from a table.\n\n    Args:\n        table:    SQLAlchemy table object\n        engine:   SQLAlchemy engine object\n        limit:    int, gives number of rows to return\n        offset:   int, gives number of rows to skip\n        order_by: list of SQLAlchemy ColumnElements to order by.  Should\n                  usually be either a list of string column names, or a\n                  list of columns from the given table.\n    \"\"\"\n    query = select(table).order_by(*order_by).limit(limit).offset(offset)\n    with engine.begin() as conn:\n        return conn.execute(query).fetchall()\n\n\ndef create_record_or_records(table, engine, record_data):\n    \"\"\"\n    record_data can be a dictionary, tuple, or list of dictionaries or tuples.\n    if record_data is a list, it creates multiple records.\n    \"\"\"\n    id_value = None\n    with engine.begin() as connection:\n        result = connection.execute(table.insert(), record_data)\n        # If there was only a single record created, return the record.\n        if result.rowcount == 1:\n            # We need to manually commit insertion so that we can retrieve the record.\n            connection.commit()\n            id_value = result.inserted_primary_key[0]\n            if id_value is not None:\n                return get_record(table, engine, id_value)\n    # Do not return any records if multiple rows were added.\n    return None\n\n\ndef update_record(table, engine, id_value, record_data):\n    primary_key_column = _get_primary_key_column(table)\n    with engine.begin() as connection:\n        connection.execute(\n            table.update().where(primary_key_column == id_value).values(record_data)\n        )\n    return get_record(table, engine, id_value)\n\n\ndef delete_record(table, engine, id_value):\n    primary_key_column = _get_primary_key_column(table)\n    query = delete(table).where(primary_key_column == id_value)\n    with engine.begin() as conn:\n        return conn.execute(query)\n", "path": "db/records.py"}]}