Uploaded image for project: 'SX Spring Python'
  1. SX Spring Python

Add dictionary support to DatabaseTemplate queries

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more



    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.1.0.M1
    • Database
    • None


      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




            gregturn Greg Turnquist
            gregturn Greg Turnquist
            tmarshall Trevor Marshall



              Time Tracking

                Original Estimate - 5d
                Remaining Estimate - 5d
                Time Spent - Not Specified
                Not Specified