@@ -20,7 +20,7 @@ To get certain columns:
2020 >> > Band.select(Band.name).run_sync()
2121 [{' name' : ' Rustaceans' }, {' name' : ' Pythonistas' }]
2222
23- Or making an alias to make it shorter:
23+ Or use an alias to make it shorter:
2424
2525.. code-block :: python
2626
@@ -46,24 +46,41 @@ This is equivalent to ``SELECT name AS title FROM band`` in SQL.
4646Joins
4747-----
4848
49- One of the most powerful things about select is it's support for joins.
49+ One of the most powerful things about `` select `` is it's support for joins.
5050
5151.. code-block :: python
5252
53- >> > b = Band
54- >> > b.select(b.name, b.manager.name).run_sync()
53+ >> > Band.select(Band.name, Band.manager.name).run_sync()
5554 [{' name' : ' Pythonistas' , ' manager.name' : ' Guido' }, {' name' : ' Rustaceans' , ' manager.name' : ' Graydon' }]
5655
5756
5857 The joins can go several layers deep.
5958
6059.. code-block :: python
6160
62- c = Concert
63- c.select(
64- c.id,
65- c.band_1.manager.name
66- ).run_sync()
61+ >> > Concert.select(Concert.id, Concert.band_1.manager.name).run_sync()
62+ [{' id' : 1 , ' band_1.manager.name' : ' Guido' }]
63+
64+ If you want all of the columns from a related table, there's a useful shortcut
65+ which saves you from typing them all out:
66+
67+ .. code-block :: python
68+
69+ >> > Band.select(Band.name, * Band.manager.all_columns()).run_sync()
70+ [
71+ {' name' : ' Pythonistas' , ' manager.id' : 1 , ' manager.name' : ' Guido' },
72+ {' name' : ' Rustaceans' , ' manager.id' : 2 , ' manager.name' : ' Graydon' }
73+ ]
74+
75+ You can also get the response as nested dictionaries, which can be very useful:
76+
77+ .. code-block :: python
78+
79+ >> > Band.select(Band.name, * Band.manager.all_columns()).output(nested = True ).run_sync()
80+ [
81+ {' name' : ' Pythonistas' , ' manager' : {' id' : 1 , ' name' : ' Guido' }},
82+ {' name' : ' Rustaceans' , ' manager' : {' id' : 2 , ' manager.name' : ' Graydon' }}
83+ ]
6784
6885 String syntax
6986-------------
@@ -183,29 +200,29 @@ By default all columns are returned from the queried table.
183200
184201.. code-block :: python
185202
186- b = Band
187203 # Equivalent to SELECT * from band
188- b .select().run_sync()
204+ Band .select().run_sync()
189205
190206 To restrict the returned columns, either pass in the columns into the
191207``select `` method, or use the ``columns `` method.
192208
193209.. code-block :: python
194210
195- b = Band
196211 # Equivalent to SELECT name from band
197- b.select().columns(b.name).run_sync()
212+ Band.select(Band.name).run_sync()
213+
214+ # Or alternatively:
215+ Band.select().columns(Band.name).run_sync()
198216
199217 The ``columns `` method is additive, meaning you can chain it to add additional
200218columns.
201219
202220.. code-block :: python
203221
204- b = Band
205- b.select().columns(b.name).columns(b.manager).run_sync()
222+ Band.select().columns(Band.name).columns(Band.manager).run_sync()
206223
207224 # Or just define it one go:
208- b .select().columns(b .name, b .manager).run_sync()
225+ Band .select().columns(Band .name, Band .manager).run_sync()
209226
210227
211228 first
0 commit comments