/Simple_CRUD_API_SQLAlchemy_ORM

Simple_CRUD_API WITH SQLAlchemy_ORM

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Simple_CRUD_API_SQLAlchemy_ORM

Simple CRUD API Build With Tornado Framework And SQLAlchemy_ORM For mapping any SQL Database


setup:

1) git clone https://github.com/MedAmineFouzai/Simple_CRUD_API_SQLAlchemy_ORM
2) cd Simple_CRUD_API_SQLAlchemy_ORM
3) pip install pipenv
4) pipenv --python 3.6
5) pipenv install - r requirements.txt
6) run project with torn cli : #command: [ torn run ]

SQLAlchemy is an open-source SQL toolkit and object-relational mapper for the Python programming language


Connecting To A Database:

change uri to the suited database (postgresql,oracl,mysql,...) in models/post.py

ex:[mysql+pymysql://root:@localhost/dbname]
DB_NAME="MyDatabaseName"
engine=create_engine('mysql+pymysql://root:@localhost/{}'.format(DB_NAME),echo=False)
Base=declarative_base()
session=Session(bind=engine)

Defining Object Data:

change the Columns and there data types based on your object fields

ex:

class post(Base):

   __tablename__='posts'
   id=Column(Integer,primary_key=True)
   title=Column(String(50))
   body=Column(String(50))
   
   def __repr__(self):
       return "<Post(id={},title={},body={}>".format(self.id,self.title,self.body)