from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine

engine = create_engine('postgresql://wn:wn@localhost:5432/wndb')

Base = declarative_base()

from sqlalchemy import Column, Integer, Float, DateTime, Boolean, String
class Observation(Base):
    __tablename__ = 'obs'

    id = Column(Integer, primary_key=True)
    station_name = Column(String)
    x = Column(Float)
    y = Column(Float)
    z = Column(Float)
    jam_indicator = Column(Boolean)
    jam_intensity = Column(Float)
    date_time = Column(DateTime)

    def __repr__(self):
       return "<Observation(station_name='%r', x='%f', y='%f', z='%f', jam_indicator='%r', jam_intensity='%f', date_time='%r')>" % (
                            self.station_name, self.x, self.y, self.z, self.jam_indicator, self.jam_intensity, self.date_time)

Base.metadata.create_all(engine)


from sqlalchemy import create_engine

engine = create_engine('postgresql://wn:wn@localhost:5432/wndb')

from sqlalchemy import Column, Integer, Float, DateTime, Boolean, String, MetaData

metadata = MetaData()
table = Table('obs', metadata, Column(Integer, primary_key=True),
    Column('station_name',String),
    Column('x',Float),
    Column('y',Float),
    Column('z',Float),
    Column('jam_indicator',Boolean),
    Column('jam_intensity',Float),
    Column('date_time',DateTime)
    )

Switch from ORM to Core
Switch from ORM to Core

- from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy import create_engine
  
  engine = create_engine('postgresql://wn:wn@localhost:5432/wndb')
  
- Base = declarative_base()
+ from sqlalchemy import Column, Integer, Float, DateTime, Boolean, String, MetaData
  
- from sqlalchemy import Column, Integer, Float, DateTime, Boolean, String
- class Observation(Base):
-     __tablename__ = 'obs'
+ metadata = MetaData()
+ table = Table('obs', metadata, Column(Integer, primary_key=True),
+     Column('station_name',String),
+     Column('x',Float),
+     Column('y',Float),
+     Column('z',Float),
+     Column('jam_indicator',Boolean),
+     Column('jam_intensity',Float),
+     Column('date_time',DateTime)
+     )
  
-     id = Column(Integer, primary_key=True)
-     station_name = Column(String)
-     x = Column(Float)
-     y = Column(Float)
-     z = Column(Float)
-     jam_indicator = Column(Boolean)
-     jam_intensity = Column(Float)
-     date_time = Column(DateTime)
- 
-     def __repr__(self):
-        return "<Observation(station_name='%r', x='%f', y='%f', z='%f', jam_indicator='%r', jam_intensity='%f', date_time='%r')>" % (
-                             self.station_name, self.x, self.y, self.z, self.jam_indicator, self.jam_intensity, self.date_time)
- 
- Base.metadata.create_all(engine)
- 
- 
Switch from ORM to Core
## Code Before:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine

engine = create_engine('postgresql://wn:wn@localhost:5432/wndb')

Base = declarative_base()

from sqlalchemy import Column, Integer, Float, DateTime, Boolean, String
class Observation(Base):
    __tablename__ = 'obs'

    id = Column(Integer, primary_key=True)
    station_name = Column(String)
    x = Column(Float)
    y = Column(Float)
    z = Column(Float)
    jam_indicator = Column(Boolean)
    jam_intensity = Column(Float)
    date_time = Column(DateTime)

    def __repr__(self):
       return "<Observation(station_name='%r', x='%f', y='%f', z='%f', jam_indicator='%r', jam_intensity='%f', date_time='%r')>" % (
                            self.station_name, self.x, self.y, self.z, self.jam_indicator, self.jam_intensity, self.date_time)

Base.metadata.create_all(engine)


## Instruction:
Switch from ORM to Core
## Code After:
from sqlalchemy import create_engine

engine = create_engine('postgresql://wn:wn@localhost:5432/wndb')

from sqlalchemy import Column, Integer, Float, DateTime, Boolean, String, MetaData

metadata = MetaData()
table = Table('obs', metadata, Column(Integer, primary_key=True),
    Column('station_name',String),
    Column('x',Float),
    Column('y',Float),
    Column('z',Float),
    Column('jam_indicator',Boolean),
    Column('jam_intensity',Float),
    Column('date_time',DateTime)
    )
