dibaloke
1/30/2019 - 3:13 PM

Postgres to SQlAlchemy

Create Table

Raw SQL

CREATE TABLE flights(
        id serial PRIMARY KEY,
        origin VARCHAR NOT NULL,
        destination VARCHAR NOT NULL,
        duration INTEGER NOT NULL
 );

SqlAlchemy

db.create_all()

Insert Operation

Raw SQL

INSERT INTO flights
(origin,destination,duration) VALUES ('NewYork','Paris',540);

SqlAlchemy

flight=Flight(origin="NewYork",destination="Paris",duration=540)
db.session.add(flight)