Skip to content

Commit 0297453

Browse files
committed
added ORM operations to README
1 parent ede76b0 commit 0297453

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Some of it’s stand out features are:
1818

1919
The syntax is clean and expressive.
2020

21+
You can use it as a query builder:
22+
2123
```python
2224
# Select:
2325
await Band.select(
@@ -43,6 +45,22 @@ await Band.update({Band.members: 5}).where(
4345
).run()
4446
```
4547

48+
Or like a typical ORM:
49+
50+
```python
51+
# To create a new object:
52+
b = Band(name='C-Sharps', popularity=100)
53+
await b.save().run()
54+
55+
# To fetch an object from the database, and update it:
56+
b = await Band.objects().where(Band.name == 'Pythonistas').first().run()
57+
b.popularity = 10000
58+
await b.save().run()
59+
60+
# To delete:
61+
await b.remove().run()
62+
```
63+
4664
## Installation
4765

4866
```

piccolo/apps/playground/commands/run.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,20 @@ def run(
157157
print(_table._table_str(abbreviated=True))
158158
print("\n")
159159

160-
print("Try out some queries:\n")
160+
print("Try it as a query builder:")
161161
print("Band.select().run_sync()")
162-
print("Band.objects().run_sync()")
163162
print("Band.select(Band.name).run_sync()")
164163
print("Band.select(Band.name, Band.manager.name).run_sync()")
165164
print("\n")
166165

166+
print("Try it as an ORM:")
167+
print(
168+
"b = Band.objects().where(Band.name == 'Pythonistas').first()."
169+
"run_sync()"
170+
)
171+
print("b.popularity = 10000")
172+
print("b.save().run_sync()")
173+
print("\n")
174+
167175
populate()
168176
IPython.embed()

0 commit comments

Comments
 (0)