-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransacciones
More file actions
29 lines (21 loc) · 754 Bytes
/
Copy pathtransacciones
File metadata and controls
29 lines (21 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from sqlalchemy import create_engine, text
engine = create_engine('sqlite:///base.db', echo=True)
# style as commit as you go
with engine.connect() as conn:
conn.execute(text("CREATE TABLE tabla (x int, y int)"))
conn.execute(
text("INSERT INTO tabla (x, y) VALUES (:x, :y)"),
[{"x": 1, "y": 1}, {"x": 2, "y": 4}],
)
conn.commit()
# style is known as begin once
with engine.begin() as conn:
conn.execute(
text("INSERT INTO tabla (x, y) VALUES (:x, :y)"),
[{"x": 6, "y": 8}, {"x": 9, "y": 10}],
)
# Obteniendo filas
with engine.connect() as conn:
result = conn.execute(text("SELECT x, y FROM tabla"))
for row in result:
print(f"x: {row.x} y: {row.y}")