Created
July 9, 2017 07:03
-
-
Save m0xb/7f3b2c32815013e98ec66e08ba620764 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sqlalchemy import Table, MetaData, Column, Integer, String, ForeignKey, Date, DateTime, Numeric, Interval, Text | |
| from sqlalchemy.orm import mapper | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker | |
| from pathlib import Path | |
| import sqlite3 | |
| metadata = MetaData() | |
| credit_card_offer = Table('credit_card_offer', metadata, | |
| Column('name', String(128), primary_key=True), | |
| Column('issuer', String(64), primary_key=True), | |
| Column('card_type', String(16)), | |
| Column('offer_start_date', Date), | |
| Column('offer_end_date', Date), | |
| Column('cash_bonus_amount', Numeric(10,2)), | |
| Column('bonus_requirement_purchase_amount', Numeric(10,2)), | |
| Column('bonus_requirement_purchase_count', Integer), | |
| Column('bonus_requirement_fulfillment_duration', Interval()), | |
| Column('bonus_requirement_account_open_duration', Interval()), | |
| Column('annual_fee', Numeric(10,2)), | |
| Column('annual_fee_first_year', Numeric(10,2)), | |
| Column('offer_url', Text), | |
| Column('created_date', DateTime) | |
| ) | |
| mapper(CreditCardOffer, credit_card_offer) | |
| db_file = Path("PATH HERE") / 'db.sqlite' | |
| print(f"Obtaining SQLite connection to file {db_file}") | |
| # Note use of three slashes here. See http://docs.sqlalchemy.org/en/latest/core/engines.html | |
| engine = create_engine('sqlite:///' + str(db_file)) | |
| Session = sessionmaker(bind=engine) | |
| session = Session() | |
| print("Creating tables") | |
| metadata.create_all(bind = engine) | |
| cco = CreditCardOffer(...) | |
| print(f"Created offer: {cco}") | |
| session.add(cco) | |
| print(f"Added to session") | |
| session.commit() | |
| print(f"Committed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment