Code

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#851 closed enhancement (invalid)

New SQL query API

Reported by: aaronsw Owned by: adrian
Component: Database layer (models, ORM) Version:
Severity: normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I'm not sure how to put this nicely, but Django's SQL query API is pretty bad. I remember excitedly thinking of switching my project to Django and then seeing this terrible syntax and just giving up entirely. Indeed, I probably would never give Django a second look if I hadn't had lunch with Adrian. pub_datedatelte='2005-01-01' is not just unintuitive, it's ugly.

Attachments (1)

sqlaccess.py (3.2 KB) - added by aaronsw 8 years ago.
Patch to proxy thd new SQL API to the old

Download all attachments as: .zip

Change History (13)

Changed 8 years ago by aaronsw

Patch to proxy thd new SQL API to the old

comment:1 Changed 8 years ago by anonymous

The attachment is a Python module that implements the a new SQL syntax. Instead of pub_date__date__lte='2005-01-01' you simply write q.pub_date <='2005-01-01'; you can also combine things using '&' and '|', although I don't know how to map these into existing Django. The way this would work is that the q object would be added to the default list of vars that currently includes things like datetime. Django tables would be replaced with something like the Table object in this function.

Note that this API also cuts down on the dozens of get_suchandsuch() functions. .get() returns one function which is an iterator, a list, a get_object, and so on in the appropriate contexts.

comment:2 Changed 8 years ago by hugo

see also #251 for & and | combination of queries

comment:3 Changed 8 years ago by rjwittams

I see can see the need for a better query api - something like hibernates HQL, which allows you to query things in a very flexible way. This would be implemented by creating an AST that can be transformed by backends into appropriate SQL - this would allow cleanly supporting SQL Server wierdness, and even non sql databases.

The existing query stuff should be done on top of a more flexible system rather than the other way round. However, I think this is something for 2.0.

comment:4 Changed 8 years ago by hugo

see also #980 for a similar approach

comment:5 Changed 8 years ago by adrian

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

comment:6 Changed 8 years ago by buy flextra

  • Cc eminem.com added
  • Keywords eminem.com added
  • Summary changed from New SQL query API to eminem.com

comment:7 Changed 8 years ago by adrian

  • Summary changed from eminem.com to New SQL query API

Reverted spam.

comment:8 Changed 8 years ago by adrian

  • Cc eminem.com removed
  • Keywords eminem.com removed

More spam reverting.

comment:9 Changed 8 years ago by anonymous

  • Cc eminem.com added
  • Keywords eminem.com added
  • Summary changed from New SQL query API to eminem.com

comment:10 Changed 8 years ago by adrian

  • Summary changed from eminem.com to New SQL query API

comment:11 Changed 8 years ago by male fertility problem

  • Cc kakalu.com added; eminem.com removed
  • Keywords kakalu.com added; eminem.com removed
  • Summary changed from New SQL query API to kakalu.com

comment:12 Changed 7 years ago by anonymous

  • Cc kakalu.com removed
  • Keywords kakalu.com removed
  • Summary changed from kakalu.com to New SQL query API

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.