Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#851 closed enhancement (invalid)

New SQL query API

Reported by: aaronsw Owned by: Adrian Holovaty
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 11 years ago.
Patch to proxy thd new SQL API to the old

Download all attachments as: .zip

Change History (13)

Changed 11 years ago by aaronsw

Attachment: sqlaccess.py added

Patch to proxy thd new SQL API to the old

comment:1 Changed 11 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 11 years ago by hugo

see also #251 for & and | combination of queries

comment:3 Changed 11 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 11 years ago by hugo

see also #980 for a similar approach

comment:5 Changed 11 years ago by Adrian Holovaty

Resolution: invalid
Status: newclosed

comment:6 Changed 10 years ago by buy flextra

Cc: eminem.com added
Keywords: eminem.com added
Summary: New SQL query APIeminem.com

comment:7 Changed 10 years ago by Adrian Holovaty

Summary: eminem.comNew SQL query API

Reverted spam.

comment:8 Changed 10 years ago by Adrian Holovaty

Cc: eminem.com removed
Keywords: eminem.com removed

More spam reverting.

comment:9 Changed 10 years ago by (none)

Cc: eminem.com added
Keywords: eminem.com added
Summary: New SQL query APIeminem.com

comment:10 Changed 10 years ago by Adrian Holovaty

Summary: eminem.comNew SQL query API

comment:11 Changed 10 years ago by male fertility problem

Cc: kakalu.com added; eminem.com removed
Keywords: kakalu.com added; eminem.com removed
Summary: New SQL query APIkakalu.com

comment:12 Changed 10 years ago by anonymous

Cc: kakalu.com removed
Keywords: kakalu.com removed
Summary: kakalu.comNew SQL query API
Note: See TracTickets for help on using tickets.
Back to Top