MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_joins

Method test_joins

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

Source from the content-addressed store, hash-verified

2414 )
2415
2416 def test_joins(self):
2417 self.assert_compile(
2418 join(table2, table1, table1.c.myid == table2.c.otherid).select(),
2419 "SELECT myothertable.otherid, myothertable.othername, "
2420 "mytable.myid, mytable.name, mytable.description FROM "
2421 "myothertable JOIN mytable ON mytable.myid = myothertable.otherid",
2422 )
2423
2424 self.assert_compile(
2425 select(table1).select_from(
2426 join(table1, table2, table1.c.myid == table2.c.otherid)
2427 ),
2428 "SELECT mytable.myid, mytable.name, mytable.description FROM "
2429 "mytable JOIN myothertable ON mytable.myid = myothertable.otherid",
2430 )
2431
2432 self.assert_compile(
2433 select(
2434 join(
2435 join(table1, table2, table1.c.myid == table2.c.otherid),
2436 table3,
2437 table1.c.myid == table3.c.userid,
2438 )
2439 ),
2440 "SELECT mytable.myid, mytable.name, mytable.description, "
2441 "myothertable.otherid, myothertable.othername, "
2442 "thirdtable.userid, "
2443 "thirdtable.otherstuff FROM mytable JOIN myothertable "
2444 "ON mytable.myid ="
2445 " myothertable.otherid JOIN thirdtable ON "
2446 "mytable.myid = thirdtable.userid",
2447 )
2448
2449 self.assert_compile(
2450 join(
2451 users, addresses, users.c.user_id == addresses.c.user_id
2452 ).select(),
2453 "SELECT users.user_id, users.user_name, users.password, "
2454 "addresses.address_id, addresses.user_id AS user_id_1, "
2455 "addresses.street, "
2456 "addresses.city, addresses.state, addresses.zip "
2457 "FROM users JOIN addresses "
2458 "ON users.user_id = addresses.user_id",
2459 )
2460
2461 self.assert_compile(
2462 select(table1, table2, table3).select_from(
2463 join(
2464 table1, table2, table1.c.myid == table2.c.otherid
2465 ).outerjoin(table3, table1.c.myid == table3.c.userid)
2466 ),
2467 "SELECT mytable.myid, mytable.name, mytable.description, "
2468 "myothertable.otherid, myothertable.othername, "
2469 "thirdtable.userid,"
2470 " thirdtable.otherstuff FROM mytable "
2471 "JOIN myothertable ON mytable.myid "
2472 "= myothertable.otherid LEFT OUTER JOIN thirdtable "
2473 "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