Code

Opened 7 years ago

Closed 4 years ago

#5421 closed (fixed)

Add "db_select" hooks for database Fields

Reported by: adrian 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

Attachments (0)

Change History (3)

comment:1 Changed 7 years ago by adrian

  • Component changed from Uncategorized to Database wrapper
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by PhiR

  • Keywords feature_request added

comment:3 Changed 4 years ago by Alex

  • Resolution set to fixed
  • Status changed from new to closed

There are other internals for doing this now.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.