MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_joins

Method test_joins

test/sql/test_compiler.py:2440–2540  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2438 )
2439
2440 def test_joins(self):
2441 self.assert_compile(
2442 join(table2, table1, table1.c.myid == table2.c.otherid).select(),
2443 "SELECT myothertable.otherid, myothertable.othername, "
2444 "mytable.myid, mytable.name, mytable.description FROM "
2445 "myothertable JOIN mytable ON mytable.myid = myothertable.otherid",
2446 )
2447
2448 self.assert_compile(
2449 select(table1).select_from(
2450 join(table1, table2, table1.c.myid == table2.c.otherid)
2451 ),
2452 "SELECT mytable.myid, mytable.name, mytable.description FROM "
2453 "mytable JOIN myothertable ON mytable.myid = myothertable.otherid",
2454 )
2455
2456 self.assert_compile(
2457 select(
2458 join(
2459 join(table1, table2, table1.c.myid == table2.c.otherid),
2460 table3,
2461 table1.c.myid == table3.c.userid,
2462 )
2463 ),
2464 "SELECT mytable.myid, mytable.name, mytable.description, "
2465 "myothertable.otherid, myothertable.othername, "
2466 "thirdtable.userid, "
2467 "thirdtable.otherstuff FROM mytable JOIN myothertable "
2468 "ON mytable.myid ="
2469 " myothertable.otherid JOIN thirdtable ON "
2470 "mytable.myid = thirdtable.userid",
2471 )
2472
2473 self.assert_compile(
2474 join(
2475 users, addresses, users.c.user_id == addresses.c.user_id
2476 ).select(),
2477 "SELECT users.user_id, users.user_name, users.password, "
2478 "addresses.address_id, addresses.user_id AS user_id_1, "
2479 "addresses.street, "
2480 "addresses.city, addresses.state, addresses.zip "
2481 "FROM users JOIN addresses "
2482 "ON users.user_id = addresses.user_id",
2483 )
2484
2485 self.assert_compile(
2486 select(table1, table2, table3).select_from(
2487 join(
2488 table1, table2, table1.c.myid == table2.c.otherid
2489 ).outerjoin(table3, table1.c.myid == table3.c.userid)
2490 ),
2491 "SELECT mytable.myid, mytable.name, mytable.description, "
2492 "myothertable.otherid, myothertable.othername, "
2493 "thirdtable.userid,"
2494 " thirdtable.otherstuff FROM mytable "
2495 "JOIN myothertable ON mytable.myid "
2496 "= myothertable.otherid LEFT OUTER JOIN thirdtable "
2497 "ON mytable.myid ="

Callers

nothing calls this directly

Calls 10

joinFunction · 0.90
selectFunction · 0.90
outerjoinFunction · 0.90
or_Function · 0.90
textFunction · 0.90
assert_compileMethod · 0.80
selectMethod · 0.45
select_fromMethod · 0.45
outerjoinMethod · 0.45
whereMethod · 0.45

Tested by

no test coverage detected