Skip to content

Commit 0aece6c

Browse files
committed
updating and cleaning up documentation
1 parent dbd0da6 commit 0aece6c

File tree

9 files changed

+39
-46
lines changed

9 files changed

+39
-46
lines changed

docs/src/piccolo/authentication/baseuser.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ Inherit from ``BaseUser`` to create your own User table.
1010
from piccolo.extensions.user import BaseUser
1111
1212
13-
class User(BaseUser):
13+
class User(BaseUser, tablename="custom_user"):
14+
pass
1415
15-
class Meta():
16-
tablename = 'custom_user'
17-
18-
.. hint:: A table name of `user` isn't allowed since it clashes with a keyword in Postgres - so override the ``tablename`` in ``Meta``, if you choose to name your class ``User``.
16+
.. hint:: A table name of `user` isn't allowed since it clashes with a keyword in Postgres - so override the ``tablename``, if you choose to name your class ``User``.
1917

2018
login
2119
-----

docs/src/piccolo/engines/index.rst

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ Engines
66
Engines are what execute the SQL queries. Each supported backend has its own
77
engine (see  :ref:`EngineTypes`).
88

9-
Meta.db
10-
-------
11-
12-
It's important that each ``Table`` class knows which engine to use. This is set
13-
via the ``Meta.db`` attribute. There are two ways of doing this - setting it
14-
explicitly, or using ``engine_finder``.
9+
It's important that each ``Table`` class knows which engine to use. There are
10+
two ways of doing this - setting it explicitly via the ``db`` argument, or
11+
letting Piccolo find it using ``engine_finder``.
1512

1613
Explicit
1714
--------
@@ -26,35 +23,17 @@ Explicit
2623
DB = SQLiteEngine(path='my_db.sqlite')
2724
2825
29-
class MyTable(Table):
26+
# Here we explicitly reference an engine:
27+
class MyTable(Table, db=DB):
3028
name = Varchar()
3129
32-
class Meta:
33-
# Here we explicitly reference an engine
34-
db = DB
35-
3630
3731
engine_finder
3832
-------------
3933

40-
By using ``engine_finder``, Piccolo will look for a file called
34+
By default Piccolo uses ``engine_finder``. Piccolo will look for a file called
4135
``piccolo_conf.py`` on the path, and will try and import a ``DB`` variable,
42-
which defines the engine. This is the default behavior, if no ``Meta`` class is
43-
defined.
44-
45-
.. code-block:: python
46-
47-
from piccolo.columns import Varchar
48-
from piccolo.engine.finder import engine_finder
49-
from piccolo.tables import Table
50-
51-
52-
class MyTable(Table):
53-
name = Varchar()
54-
55-
class Meta:
56-
# Let Piccolo import the engine from a config file:
57-
db = engine_finder()
36+
which defines the engine.
5837

5938
Here's an example config file:
6039

docs/src/piccolo/getting_started/sync_and_async.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ A lot of the time, using the sync version works perfectly fine. Many of the
4747
examples use the sync version.
4848

4949
Using the async version is useful for web applications which require high
50-
throughput, based on `ASGI frameworks </blog/introduction-to-asgi>`_.
50+
throughput, based on `ASGI frameworks <https://piccolo-orm.com/blog/introduction-to-asgi>`_.
5151

5252
Explicit
5353
--------

docs/src/piccolo/query_types/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Query Types
22
===========
33

4+
There are many different queries you can perform using Piccolo. For starters,
5+
focus on `select`, `insert` and `update`.
6+
47
.. toctree::
58
:maxdepth: 0
69

docs/src/piccolo/query_types/insert.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,25 @@ This is used to insert rows into the table.
99
1010
>>> Band.insert(Band(name="Pythonistas")).run_sync()
1111
[{'id': 3}]
12+
13+
We can insert multiple rows in one go:
14+
15+
.. code-block:: python
16+
17+
Band.insert(
18+
Band(name="Darts"),
19+
Band(name="Gophers")
20+
).run_sync()
21+
22+
add
23+
---
24+
25+
You can also compose it as follows:
26+
27+
.. code-block:: python
28+
29+
Band.insert().add(
30+
Band(name="Darts")
31+
).add(
32+
Band(name="Gophers")
33+
).run_sync()

docs/src/piccolo/schema/defining.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ columns.
2222
2323
For a full list of columns, see :ref:`ColumnTypes`.
2424

25-
Meta
26-
----
27-
2825
Connecting to the database
29-
~~~~~~~~~~~~~~~~~~~~~~~~~~
26+
--------------------------
3027

3128
In order to create the table and query the database, you need to provide
3229
Piccolo with your connection details. See :ref:`Engines`.

piccolo/commands/playground.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def playground(engine, user, password, database, host, port):
9494
import IPython
9595
except ImportError:
9696
print(
97-
"Install iPython using `pip install ipython==7.1.1` to use this "
97+
"Install iPython using `pip install ipython==7.6.1` to use this "
9898
"feature."
9999
)
100100
sys.exit(1)

piccolo/query/methods/insert.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ def run_callback(self, results):
2626

2727
@property
2828
def sqlite_querystring(self) -> QueryString:
29-
if len(self.add_delegate._add) > 1:
30-
raise Exception(
31-
"The SQLite engine is unable to insert more than one row at a "
32-
"time."
33-
)
34-
3529
base = f"INSERT INTO {self.table._meta.tablename}"
3630
columns = ",".join([i._meta.name for i in self.table._meta.columns])
3731
values = ",".join(["{}" for i in self.add_delegate._add])

piccolo/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __str__(cls):
5151
spacer = "\n "
5252
columns = []
5353
for col in cls._meta.columns:
54-
if type(col) == ForeignKey:
54+
if isinstance(col, ForeignKey):
5555
columns.append(
5656
f"{col._meta.name} = ForeignKey({col._foreign_key_meta.references.__name__})"
5757
)

0 commit comments

Comments
 (0)