This paste expires on 2023-04-03 18:35:49.906838. Repaste, or download this paste. . Pasted through web.

import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
from sqlalchemy import inspect
from sqlalchemy.sql import text
metadata = MetaData()
books = Table('book', metadata,
  Column('id', Integer, primary_key=True),
  Column('title', String),
  Column('primary_author', String),
)
engine = create_engine('sqlite:///bookstore.db')
metadata.create_all(engine)
with engine.connect() as con:
    data = ( { 'id': 1, 'title': 'The Hobbit', 'primary_author': 'Tolkien' },
             { 'id': 2, 'title': 'The Silmarillion', 'primary_author': 'Tolkien' },
    )
    print(str(data))
    statement = text('''INSERT INTO book(id, title, primary_author) VALUES(:id, :title, :primary_author)''')
    for line in data:
        con.execute(statement, **line)
with engine.connect() as con:
    rs = con.execute('SELECT * FROM book')
    for row in rs:
        print(row)
Filename: None. Size: 978b. View raw, , hex, or download this file.