Skip to content

Mantej-Singh/The-SQL-Alchemist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

The-Alchemist

SQLAlchemy miniproject

The SQLAlchemy Object Relational Mapper presents a method of associating user-defined Python classes with database tables, and instances of those classes (objects) with rows in their corresponding tables.

[screenshot_14883s88948.png

Overview:

The SQLAlchemy SQL Toolkit and Object Relational Mapper is a comprehensive set of tools for working with databases and Python. It has several distinct areas of functionality which can be used individually or combined together. Its major components are illustrated below, with component dependencies organized into layers: [scrffeenshot_14883s88948.png

Above, the two most significant front-facing portions of SQLAlchemy are the Object Relational Mapper and the SQL Expression Language. SQL Expressions can be used independently of the ORM. When using the ORM, the SQL Expression language remains part of the public facing API as it is used within object-relational configurations and queries.


Install via pip

pip install SQLAlchemy

Creating Engine

from sqlalchemy import create_engine

Connecting with SQLite3

db_engine = create_engine('sqlite:///sqlalchemy_example.db')

Create a Schema

user=Table('users',metadata,
          Column('ID',Integer,primary_key=True),
          Column('name', String(40)),
          Column('age', Integer)
          )

output:

screenshot-1489115274.png

Actual Data stored in SQLite db_engine: sqlalchemy_example.db

screenshot-1489163026.png



Reverse Engineering

Create a DataFrame

import pandas as pd

col=['ID','Name','Age']

data=[(8,'Ironman',58),
     (9,'Thor',300),
     (10,'Hulk',55)]
     
df=pd.DataFrame(data,columns=col)

screenshot-1489162928.png

Output1:

screenshot-1489162712.png

output2:

screenshot-1489162366.png