Opened 9 years ago

Closed 6 years ago

#5421 closed (fixed)

Add "db_select" hooks for database Fields

Reported by: Adrian Holovaty Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: feature_request
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I'm proposing a "db_select" method on the database Field class. This would specify the raw SQL to use when listing the field in the SELECT clause of an SQL statement. This will allow for more useful SELECTs in the case of opaque data types such as PostGIS "geometry" fields, which are returned by default as an encoded series of bytes.

It could also allow certain fields, such as BLOBs, to *never* be returned in a SELECT statement. (I'm 50/50 on this particular idea.)

class Field:
    def db_select(self, table):
        # Default behavior is to select the column name.
        return '%s.%s' % (table, self.db_column)

class GeometryField(Field):
    def db_select(self, table):
        # For a PostGIS geometry field, select the textual version of the geometry.
        return 'AsText(%s.%s)' % (table, self.db_column)

class BlobField(Field):
    def db_select(self, table):
        # None means "Don't ever include this field in a SELECT list."
        return None

Change History (3)

comment:1 Changed 9 years ago by Adrian Holovaty

Component: UncategorizedDatabase wrapper
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 9 years ago by Philippe Raoult

Keywords: feature_request added

comment:3 Changed 6 years ago by Alex Gaynor

Resolution: fixed
Status: newclosed

There are other internals for doing this now.

Note: See TracTickets for help on using tickets.
Back to Top