Uploaded image for project: 'SX Spring Python'
  1. SX Spring Python
  2. SESPRINGPYTHONPY-95

Add dictionary support to DatabaseTemplate queries

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.0.M1
    • Component/s: Database
    • Labels:
      None

      Description

      Expand DatabaseTemplate by using the DB API 2.0 .description attribute so that a dictionary can be generated driven by the query. This easily supports a convention-over-configuration way of configuring POPOs without having to specify every field. Since this requires a break in map_row signature of RowMapper, this would be a break in API.

      [3:03:37 PM] Sven Wilhelm: I think the following signature woud solve the problem: map_row(self, row, metadata=None)
      [3:04:27 PM] Greg Turnquist: >>> data = [('id', 'int4', None, 4, None, None, None), ('name', 'varchar', None, -1, None, None, None)]
      >>> [item[0] for item in data]
      ['id', 'name']
      [3:04:29 PM] Sven Wilhelm: does the .description info contains all fields from all tables or only the infos of the last query
      [3:04:34 PM] Greg Turnquist: Isn't that a piece of what we want?
      [3:04:48 PM] Sven Wilhelm: exactly

      [3:14:55 PM] Sven Wilhelm: I would hide the original query_for_list into __query_for_list and provide a new one
      [3:16:45 PM] Sven Wilhelm: the new looks like query_for_list(self, sql_query, args = None):
      [3:17:04 PM] Sven Wilhelm: as it is the expected stable api
      [3:17:41 PM] Sven Wilhelm: query_for_list(self, sql_query, args=None):
      [3:18:41 PM] Sven Wilhelm: result, metadata = self.__query_for_list(self, sql_query, args=None):
      [3:18:49 PM] Sven Wilhelm: return result
      [3:19:37 PM] Sven Wilhelm: __query_for_list returns [resultlist, metadata]

      [3:22:57 PM] Sven Wilhelm: the traditional query(self, sql_query, args = None, rowhandler = None):
      [3:23:09 PM] Sven Wilhelm: would then use the __query variant
      [3:23:34 PM] Sven Wilhelm: and could then pass the metadata as the second arg to map_row
      [3:24:01 PM] Sven Wilhelm: only real api break, is then on the mapper
      [3:24:24 PM] Greg Turnquist: With is being optional, it probably wouldn't break anybody. Instead, it becomes an option to utilize.
      [3:25:10 PM] Sven Wilhelm: yes but when implementing the interface you have real code changes in existing apps
      [3:25:48 PM] Greg Turnquist: My other thinking is how to handle mismatches. For example, is the POPO has different columns than the query. Default policy would be to match as many as possible, but I could see wanting to have some alternative like, only match if perfect 1:1, otherwise throw some error. Probably an extension of RowMapper could provide this?
      [3:26:47 PM] Greg Turnquist: I see. If you actually extended the interface class, python would complain over change in signature?
      [3:27:11 PM] Greg Turnquist: ...due to python's lack of overloading?
      [3:29:32 PM] Sven Wilhelm: not a perfect world
      [3:32:35 PM] Sven Wilhelm: I would propagate the break for v1.1

        Activity

        Hide
        gregturn Greg Turnquist added a comment -

        Finished changes as well as doc updates. Merged to trunk, confirmed all tests passed, and committed changes. Observed that all tests passed on CI server.

        Show
        gregturn Greg Turnquist added a comment - Finished changes as well as doc updates. Merged to trunk, confirmed all tests passed, and committed changes. Observed that all tests passed on CI server.

          People

          • Assignee:
            gregturn Greg Turnquist
            Reporter:
            gregturn Greg Turnquist
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 5d
              5d
              Remaining:
              Remaining Estimate - 5d
              5d
              Logged:
              Time Spent - Not Specified
              Not Specified