> On Apr 9, 2018, at 10:32 AM, Tim Nevels via 4D_Tech <[email protected]>
> wrote:
>
> Something that may not be immediately obvious is that using ORDA will reduce
> the amount of code needed to query the database. In relational databases you
> have to query this table, join to another table, query selection, relate
> many, etc. We are all used to doing this and we need to know exactly what the
> database structure is. What table is the one table, what table is the many
> table, is there a many-to-many intermediate table we need to deal with, etc.
I use Django, an open-source python web framework, for my pure-web projects.
This is what a user search looks like. I tell users they can search by last and
first or by last name (this is for one specific search block, more complex
searches are available. :-))
def people_name_search(name):
if name:
if ',' in name:
lname, fname = split_name(name)
return Person.objects.filter(last_name__istartswith=lname,
first_name__istartswith=fname,
deactivated=False)[:10]
else:
return Person.objects.filter(last_name__istartswith=name,
deactivated=False)[:10]
else:
return Person.objects.none()
You can suss that out even though there is magic syntax (objects?
istartswith?). What you can’t see is that the object “Person” has a default
sort order defined (last name, first name), so that result gives you an ordered
list of the first 10 records that match the query.
Below is a cross table (join) query:
The table relationship are Person <—Enrollment—> Registration and Person
<—ProductSale—> Registration..
The query gives me the registration records that have associated enrollment or
product sales records that are linked to a person whose name is ….
The Q thing is the syntactic sugar needed to do OR searches. (all the
frameworks have their wth.)
def enrollee_name_search(name):
if name:
if ',' in name:
lname, fname = split_name(name)
return
Registration.objects.select_related().filter(Q(enrollment__person__last_name__istartswith=lname,
enrollment__person__first_name__istartswith=fname)
|
Q(productsale__person__last_name__istartswith=lname,
productsale__person__first_name__istartswith=fname)
)
else:
return
Registration.objects.select_related().filter(Q(enrollment__person__last_name__istartswith=name)
|
Q(productsale__person__last_name__istartswith=name)
)
else:
return Registration.objects.none()
All of which is to say, ORDA is going to make complete sense if you’ve done
any work in a semi-modern framework.
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************