@@ -10,6 +10,8 @@ It's important that each ``Table`` class knows which engine to use. There are
1010two ways of doing this - setting it explicitly via the ``db `` argument, or
1111letting Piccolo find it using ``engine_finder ``.
1212
13+ -------------------------------------------------------------------------------
14+
1315Explicit
1416--------
1517
@@ -30,6 +32,7 @@ connect to a database.
3032 class MyTable (Table , db = DB ):
3133 name = Varchar()
3234
35+ -------------------------------------------------------------------------------
3336
3437engine_finder
3538-------------
@@ -94,6 +97,8 @@ variable accordingly.
9497
9598 .. hint :: You can also specify sub modules, like `my_module.piccolo_conf`.
9699
100+ -------------------------------------------------------------------------------
101+
97102.. _EngineTypes :
98103
99104Engine types
@@ -103,83 +108,8 @@ Engine types
103108 production. It is the most feature complete.
104109
105110
106- SQLiteEngine
107- ~~~~~~~~~~~~
108-
109- .. code-block :: python
110-
111- # piccolo_conf.py
112- from piccolo.engine.sqlite import SQLiteEngine
113-
114-
115- DB = SQLiteEngine(path = ' my_app.sqlite' )
116-
117-
118- PostgresEngine
119- ~~~~~~~~~~~~~~
120-
121- .. code-block :: python
122-
123- # piccolo_conf.py
124- from piccolo.engine.postgres import PostgresEngine
125-
126-
127- DB = PostgresEngine({
128- ' host' : ' localhost' ,
129- ' database' : ' my_app' ,
130- ' user' : ' postgres' ,
131- ' password' : ' '
132- })
133-
134- Connection pool
135- ---------------
136-
137- .. warning :: This is currently only available for Postgres.
138-
139-
140- To use a connection pool, you need to first initialise it. The best place to do
141- this is in the startup event handler of whichever web framework you are using.
142-
143- Here's an example using Starlette. Notice that we also close the connection
144- pool in the shutdown event handler.
145-
146- .. code-block :: python
147-
148- from piccolo.engine import from starlette.applications import Starlette
149- from starlette.applications import Starlette
150-
151-
152- app = Starlette()
153-
154-
155- @app.on_event (' startup' )
156- async def open_database_connection_pool ():
157- engine = engine_finder()
158- await engine.start_connnection_pool()
159-
160-
161- @app.on_event (' shutdown' )
162- async def close_database_connection_pool ():
163- engine = engine_finder()
164- await engine.close_connnection_pool()
165-
166- .. hint :: Using a connection pool helps with performance, since connections
167- are reused instead of being created for each query.
168-
169- Once a connection pool has been started, the engine will use it for making
170- queries.
171-
172- .. hint :: If you're running several instances of an app on the same server,
173- you may prefer an external connection pooler - like pgbouncer.
174-
175- Configuration
176- ~~~~~~~~~~~~~
177-
178- The connection pool uses the same configuration as your engine. You can also
179- pass in additional parameters, which are passed to the underlying database
180- adapter. Here's an example:
181-
182- .. code-block :: python
111+ .. toctree ::
112+ :maxdepth: 1
183113
184- # To increase the number of connections available:
185- await engine.start_connnection_pool( max_size = 20 )
114+ ./sqlite_engine
115+ ./postgres_engine
0 commit comments