forked from bustawin/sqlalchemy-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha0_intro.py
More file actions
30 lines (23 loc) · 776 Bytes
/
a0_intro.py
File metadata and controls
30 lines (23 loc) · 776 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
30
"""
This example is from `TutorialsPoint <https://www.tutorialspoint.com/
sqlalchemy/sqlalchemy_core_expression_language.htm>`_
"""
from sqlalchemy import Column, Integer, MetaData, String, Table, create_engine
engine = create_engine('sqlite://', echo=True)
meta = MetaData() # Create a sandbox (where SQLA stores Table... the DB Schema)
students = Table(
'students', meta,
Column('id', Integer, primary_key=True),
Column('name', String),
Column('lastname', String),
)
conn = engine.connect()
meta.create_all(engine) # Create the tables
ins = students.insert().values(name='Ravi', lastname='Kapoor')
print(conn.execute(ins))
conn1 = engine.connect()
s = students.select()
result = conn1.execute(s)
print('Students:')
for row in result:
print(row)