Skip to content

regyeduardo/curso-python-api-development-comprehensive-course-for-beginners-FREECODECAMP-YOUTUBE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crud 1:25:17

Create

@app.posts("/posts")

Read

@app.get("/posts/{id}")
@app.get("/posts")

Update

@app.put("/posts/{id}")

Delete

@app.delete("/posts/{id}")

RUN

uvicorn app.main:app --reload

Databases

What is a database

  • Database is a collection of organized data that can be easaly accessed and managed

DBMS

  • We don't work or interact with databases directly
  • Instead we make use of a software referred to as a Database Management System(DBMS)

Popular DBMS 2:25:30

Relational NoSQL
MySQL MongoDB
PostgreSQL DynamoDB
Oracle Oracle
SQL Server SQL Server

Ralational Database & SQL

  • Structured Query Languege(SQL) - Language used to cummunicate with DBMS

Postgres

  • Each instance of postgres can be carved into multiple separete databases
  • By Default every Postgres installation comes with one database already created called "postgres"
  • This is important because Postgres requires you to specify the name of a database to make a connection. So there needs to always be one database

Tables

  • A table represents a subject or event in an application

Columns Vs Rows

  • A table is made up of columns and rows
  • Each Column represents a different attribute
  • Each row represents a different entry in the table

Postgres DataTypes

  • Databases have datatypes just like any programming language | DataType | Postgres | Python | |----------|-------------------------|------------| | Numeric | int, decimal, precision | Int, float | | Text | Varchar, text | string | | Bool | boolean | boolean | | Sequence | array | list |

Primary Key

  • Is a column or group of columns that uniquely identifies each row in a table
  • Table can have one and only one primary key

Unique Constraints

  • A UNIQUE constraint can be applied to any column to make sure every record has a unique value for that column

Null Constraints

  • By default, when adding a new entry to a database, any column can be left blank. When a column is left blank, it has a null value
  • If you need column to be properly filled in to create a new record, a NOT NULL constraint can be added to yhe column to ensure that the column is never left blank

Setting up postgres portable

Setting up postgres portable

Object Relational Mapper(ORM) 4:31:24

  • Layer of obstraction that sits between the database and us
  • We can perform all database operations through traditional python code. No more SQL!

What can ORMs Do

  • Instead of manually defining tables in postgres, we can define our tables as python models
  • Queries can be made exclusively through python code. No SQL is necessary
class Post(Base):
    __tablename__ = "posts"

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String, index=True, nullable=False)
    content = Column(String, nullable=False)
    published = Column(Boolean)
db.query(models.Post).filter(models.Post.id == id).first()

SQLALCHEMY

  • SQLALCHEMY is one of the most popular python ORMs
  • It is stand-alone library and has no association with FastAPI, It can be used with any other python web frameworks or any python based application

Schema Models 5:29:56

  • Schema/Pydantic Models define the structure of a request & response
  • This ensure that when a user wants to create a post, the request will only go through if it has a "title" and "content" in the body

SQLALCHEMY Models

  • Responsible for defining the columns of our "posts" table within postgres
  • Is used to query, create, delete and update entries within the database

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages