home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.vms      DEC's VAX* line of computers & VMS.      264,096 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 262,916 of 264,096   
   =?UTF-8?Q?Arne_Vajh=C3=B8j?= to All   
   Re: VMS x86-64 database server   
   29 Jul 25 10:02:00   
   
   From: arne@vajhoej.dk   
      
   On 7/29/2025 9:39 AM, Arne Vajhøj wrote:   
   > On 7/29/2025 12:25 AM, Lawrence D'Oliveiro wrote:   
   >> On Mon, 28 Jul 2025 22:36:59 -0400, Arne Vajhøj wrote:   
   >>> Even with ORM you need to express the query.   
   >>   
   >> So a lot of the stuff in SQLAlchemy is useless, then?   
   >   
   > No.   
   >   
   > It does what it is supposed to do: do the mapping between   
   > the query result and the object model.   
   >   
   >>> JPQL example (ORM specific query language):   
   >>>   
   >>> List res = em.createQuery("SELECT o FROM T1 AS o WHERE o.f > 0",   
   >>> T1.class).getResultList();   
   >>   
   >> That seems like a really dumb idea. You see my point about having   
   >> their own query language does nothing to simplify the code.   
   >   
   > Again: the benefit is not in the query but in the fact that it   
   > stuff the query result into the object model without any   
   > application code.   
      
   Let me give an example. Python.   
      
   SQL   
   ---   
      
   import sqlite3   
      
   from popo_domain import myorder, orderline   
      
   def map_list_rel_to_obj(data):   
        res = []   
        lastorderid = -1   
        for row in data:   
            if row[0] != lastorderid:   
                res.append(myorder(row[0], row[1], row[2]))   
                lastorderid = row[0]   
            res[-1].orderlines.append(orderline(row[3], row[4], row[5],   
   row[6]))   
        return res   
      
   with sqlite3.connect('test.db') as con:   
        c = con.cursor()   
        c.execute('SELECT myorder.orderid, customer, state, orderlineid,   
   itemname, itemprice, quantity FROM myorder JOIN orderline ON   
   myorder.orderid = orderline.orderid')   
        rdata = c.fetchall()   
        odata = map_list_rel_to_obj(rdata)   
      
   SQLModel   
   --------   
      
   from sqlmodel import Session, create_engine, select   
   from sqlalchemy.orm import joinedload   
      
   from sqm_domain import myorder, orderline   
      
   eng = create_engine('sqlite+pysqlite:///test.db')   
   with Session(eng) as ses:   
        odata =   
   ses.exec(select(myorder).options(joinedload(myorder.orderlines))   
   .unique().all()   
      
   In both cases we end up with a list of order objects that each contains   
   a list of orderline objects.   
      
   With SQL the application need to copy the data into the object   
   model.   
      
   With SQLModel that is done automatically.   
      
   The fact that one use SQL to define query while the other use a fluent   
   API to define query is not that significant.   
      
   Arne   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca