File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
content/articles/psycopg-33-released Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ How does it look? Something like:
3232.. code:: python
3333
3434 def fetch_person(conn, name):
35+
3536 # 'name' will be handled safely: as a server-side parameter or
3637 # correctly quoted and escaped if client-side binding is required
3738 cur = conn.execute(t"SELECT * FROM people WHERE name = {name}")
@@ -46,8 +47,10 @@ succinctly than with the `psycopg.sql`__ module:
4647.. code:: python
4748
4849 def delete_something(conn, table_name, name):
50+
4951 # Mixing client-side query composition with server-side parameters binding
5052 conn.execute(t"DELETE FROM {table_name:i} WHERE name = {name}")
53+
5154 # Composing non-parametric statements entirely client-side
5255 conn.execute(t"NOTIFY {table_name + '.deleted':i}, {name:l}")
5356
@@ -101,7 +104,7 @@ objects... Dataclasses anyone?
101104 # MiniPerson(age=33, name='John', height=None)
102105
103106 conn.execute(
104- "SELECT (%(person)s).name || ' next year will be ' || (%(person)s).age + 1",
107+ "SELECT (%(person)s).name || ' next year will be ' || (%(person)s).age + 1",
105108 {"person": MiniPerson(name="John", age=33)},
106109 ).fetchone()[0]
107110 # 'John next year will be 34'
You can’t perform that action at this time.
0 commit comments