Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

A sample RestAPI using FastAPI and pyodbc to connect to a Microsoft SQL Server Database.

License

Notifications You must be signed in to change notification settings

qlawmarq/fastapi-pyodbc-ms-sql-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastapi-pyodbc-ms-sql-server

A sample RestAPI using FastAPI and pyodbc to connect to a Microsoft SQL Server Database.

How to use

  1. Prepare a SQL Server Database, DB user and password, also DB host.
  2. Rewrite ENV of Dockerfile with your own DB infos.
  3. Build A Docker instance and run it.
  4. Test DB connection, and then do whatever you want.

Setup development environment

Please install Docker and Docker compose first.

https://www.docker.com/

After installation, run the following command to create a local Docker container.

docker-compose build
docker-compose up -d

If you want to check the log while Docker container is running, then try to use following command:

docker-compose up

If Docker is running successfully, the API and DB server will be launched as shown in the following:

Be careful, it won't work if the port is occupied by another application.

If you want to check docker is actually working, then you can check it with following command:

docker ps

If you want to go inside of docker container, then try to use following command:

docker-compose exec fast_api bash

For shutdown of the docker instance, please use following command:

docker-compose down

Production deployment

Build a docker image:

docker build -f ./Dockerfile -t fastapi-sql-server-app . --platform linux/amd64 --no-cache

And then push it to your repository:
(The following is just an example.)

docker tag fastapi-sql-server-app gcr.io/your-project-of-gcp/fastapi-sql-server-app
docker push gcr.io/your-project-of-gcp/fastapi-sql-server-app

About

A sample RestAPI using FastAPI and pyodbc to connect to a Microsoft SQL Server Database.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published