Skip to content

Commit 61cf97c

Browse files
committed
turning more query methods into properties
1 parent d4cc337 commit 61cf97c

File tree

10 files changed

+24
-21
lines changed

10 files changed

+24
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ build/
99
piccolo.egg-info/
1010
build/
1111
dist/
12+
piccolo.sqlite

piccolo/columns/column_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class ForeignKey(Integer):
9898
To change the manager:
9999
100100
some_band.manager = some_manager_id
101-
some_band.save()
101+
some_band.save
102102
103103
Or:
104104
some_band.set_related_object('manager', some_manager)

piccolo/commands/playground.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,37 +68,37 @@ def populate():
6868
print(e)
6969

7070
guido = Manager(name="Guido")
71-
guido.save().run_sync()
71+
guido.save.run_sync()
7272

7373
pythonistas = Band(
7474
name="Pythonistas",
7575
manager=guido.id,
7676
popularity=1000
7777
)
78-
pythonistas.save().run_sync()
78+
pythonistas.save.run_sync()
7979

8080
graydon = Manager(name="Graydon")
81-
graydon.save().run_sync()
81+
graydon.save.run_sync()
8282

8383
rustaceans = Band(
8484
name="Rustaceans",
8585
manager=graydon.id,
8686
popularity=500
8787
)
88-
rustaceans.save().run_sync()
88+
rustaceans.save.run_sync()
8989

9090
venue = Venue(
9191
name="Amazing Venue",
9292
capacity=5000
9393
)
94-
venue.save().run_sync()
94+
venue.save.run_sync()
9595

9696
concert = Concert(
9797
band_1=pythonistas.id,
9898
band_2=rustaceans.id,
9999
venue=venue.id
100100
)
101-
concert.save().run_sync()
101+
concert.save.run_sync()
102102

103103

104104
@click.command(name="playground")

piccolo/table.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def __init__(self, **kwargs):
227227
if unrecognized:
228228
raise ValueError(f'Unrecognized columns - {unrecognized}')
229229

230+
@property
230231
def save(self):
231232
"""
232233
A proxy to an insert or update query.
@@ -248,6 +249,7 @@ def save(self):
248249
else:
249250
return cls.insert().add(self)
250251

252+
@property
251253
def remove(self):
252254
"""
253255
A proxy to a delete query.

tests/extensions/test_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_login(self):
5454
username=username,
5555
password=password,
5656
email=email
57-
).save()
57+
).save
5858

5959
save_query.run_sync()
6060

tests/table/instance/test_delete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def test_delete(self):
1616
name='Maz'
1717
)
1818

19-
manager.save().run_sync()
20-
manager.remove().run_sync()
19+
manager.save.run_sync()
20+
manager.remove.run_sync()
2121

2222
# how can I implement 'flat=True'
2323
# Band.select.columns(Band.name).output(as_list=True).run_sync()

tests/table/instance/test_get_related.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def test_get_related(self):
2323
manager = Manager(
2424
name="Guido"
2525
)
26-
manager.save().run_sync()
26+
manager.save.run_sync()
2727

2828
band = Band(
2929
name='Pythonistas',
3030
manager=manager.id,
3131
popularity=100
3232
)
33-
band.save().run_sync()
33+
band.save.run_sync()
3434

3535
_manager = band.get_related('manager').run_sync()
3636

tests/table/instance/test_save.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_save_new(self):
1919
name='Maz',
2020
)
2121

22-
query = manager.save()
22+
query = manager.save
2323
print(query)
2424
self.assertTrue('INSERT' in query.__str__())
2525

@@ -31,7 +31,7 @@ def test_save_new(self):
3131
self.assertTrue('Maz' in names)
3232

3333
manager.name = 'Maz2'
34-
query = manager.save()
34+
query = manager.save
3535
print(query)
3636
self.assertTrue('UPDATE' in query.__str__())
3737

tests/table/test_join.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,27 @@ def tearDown(self):
3333

3434
def test_join(self):
3535
manager_1 = Manager(name="Guido")
36-
manager_1.save().run_sync()
36+
manager_1.save.run_sync()
3737

3838
band_1 = Band(name="Pythonistas", manager=manager_1.id)
39-
band_1.save().run_sync()
39+
band_1.save.run_sync()
4040

4141
manager_2 = Manager(name="Graydon")
42-
manager_2.save().run_sync()
42+
manager_2.save.run_sync()
4343

4444
band_2 = Band(name="Rustaceans", manager=manager_2.id)
45-
band_2.save().run_sync()
45+
band_2.save.run_sync()
4646

4747
venue = Venue(name="Grand Central")
48-
venue.save().run_sync()
48+
venue.save.run_sync()
4949

5050
# TODO - make sure you can also do:
5151
# band_1=Pythonistas
5252
save_query = Concert(
5353
band_1=band_1.id,
5454
band_2=band_2.id,
5555
venue=venue.id
56-
).save()
56+
).save
5757
save_query.run_sync()
5858

5959
select_query = Concert.select.columns(

tests/table/test_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_get_all(self):
1818

1919
# Now try changing the value and saving it.
2020
instance.name = 'Rustaceans'
21-
save_query = instance.save()
21+
save_query = instance.save
2222
save_query.run_sync()
2323

2424
self.assertTrue(

0 commit comments

Comments
 (0)