@@ -48,19 +48,20 @@ And we want to INSERT new data to this table:
4848``` python
4949from typing import Final
5050
51- from psqlpy import ConnectionPool, QueryResult
51+ from psqlpy import Connection, ConnectionPool, QueryResult
5252from psqlpy.extra_types import SmallInt, Integer, BigInt, Float32, Float64
5353
5454
5555async def main () -> None :
5656 # It uses default connection parameters
5757 db_pool: Final = ConnectionPool()
58+ connection: Connection = await db_pool.connection()
5859
59- await db_pool .execute(
60+ await connection .execute(
6061 " INSERT INTO numbers (index, elf_life, elon_musk_money) VALUES ($1, $2, $3, $4, $5)" ,
6162 [SmallInt(101 ), Integer(10500 ), BigInt(300000000000 ), Float32(123.11 ), Float64(222.12 )],
6263 )
63- db_pool .close()
64+ connection .close()
6465```
6566
6667::: important
@@ -81,24 +82,25 @@ Let's assume we have table `banners` in the database:
8182``` python
8283from typing import Final
8384
84- from psqlpy import ConnectionPool, QueryResult
85+ from psqlpy import Connection, ConnectionPool, QueryResult
8586from psqlpy.extra_types import PyText
8687
8788
8889async def main () -> None :
8990 # It uses default connection parameters
9091 db_pool: Final = ConnectionPool()
92+ connection: Connection = await db_pool.connection()
9193
92- await db_pool .execute(
94+ await connection .execute(
9395 " INSERT INTO banners (title, description) VALUES ($1, $2)" ,
9496 [" SomeTitle" , PyText(" Very long description" )],
9597 )
9698 # Alternatively, you can do this:
97- await db_pool .execute(
99+ await connection .execute(
98100 " INSERT INTO banners (title, description) VALUES ($1, $2)" ,
99101 [PyVarChar(" SomeTitle" ), PyText(" Very long description" )],
100102 )
101- db_pool .close()
103+ connection .close()
102104```
103105
104106## PyJSON & PyJSONB
@@ -126,13 +128,15 @@ Let's assume we have table `users` in the database, and field `additional_user_i
126128``` python
127129from typing import Final
128130
129- from psqlpy import ConnectionPool, QueryResult
131+ from psqlpy import Connection, ConnectionPool, QueryResult
130132from psqlpy.extra_types import PyJSON
131133
132134
133135async def main () -> None :
134136 # It uses default connection parameters
135137 db_pool: Final = ConnectionPool()
138+ connection: Connection = await db_pool.connection()
139+
136140 list_for_jsonb_field = [
137141 {" some" : " dict" },
138142 [
@@ -147,16 +151,16 @@ async def main() -> None:
147151 ]
148152 }
149153
150- await db_pool .execute(
154+ await connection .execute(
151155 " INSERT INTO users (additional_user_info) VALUES ($1)" ,
152156 [PyJSONB(list_for_jsonb_field)],
153157 )
154- await db_pool .execute(
158+ await connection .execute(
155159 " INSERT INTO users (additional_user_info) VALUES ($1)" ,
156160 [dict_for_jsonb_field,],
157161 )
158162
159- db_pool .close()
163+ connection .close()
160164```
161165
162166## PyMacAddr6 & PyMacAddr8
@@ -171,23 +175,24 @@ Let's assume we have table `devices` in the database:
171175``` python
172176from typing import Final
173177
174- from psqlpy import ConnectionPool, QueryResult
178+ from psqlpy import Connection, ConnectionPool, QueryResult
175179from psqlpy.extra_types import PyMacAddr6, PyMacAddr8
176180
177181
178182async def main () -> None :
179183 # It uses default connection parameters
180184 db_pool: Final = ConnectionPool()
185+ connection: Connection = await db_pool.connection()
181186
182- await db_pool .execute(
187+ await connection .execute(
183188 " INSERT INTO devices (device_macaddr6, device_macaddr8) VALUES ($1, $2)" ,
184189 [
185190 PyMacAddr6(" 08:00:2b:01:02:03" ),
186191 PyMacAddr8(" 08:00:2b:01:02:03:04:05" ),
187192 ],
188193 )
189194
190- db_pool .close()
195+ connection .close()
191196```
192197
193198## Geo Types
@@ -207,15 +212,16 @@ Let's assume we have table `geo_info` with all PostgreSQL geo types in the datab
207212``` python
208213from typing import Final
209214
210- from psqlpy import ConnectionPool, QueryResult
215+ from psqlpy import Connection, ConnectionPool, QueryResult
211216from psqlpy.extra_types import Point, Box, Path, Line, LineSegment, Circle
212217
213218
214219async def main () -> None :
215220 # It uses default connection parameters
216221 db_pool: Final = ConnectionPool()
222+ connection: Connection = await db_pool.connection()
217223
218- await db_pool .execute(
224+ await connection .execute(
219225 " INSERT INTO geo_info VALUES ($1, $2, $3, $4, $5, $6)" ,
220226 [
221227 Point([1.5 , 2 ]),
@@ -227,5 +233,5 @@ async def main() -> None:
227233 ],
228234 )
229235
230- db_pool .close()
236+ connection .close()
231237```
0 commit comments