Tim's Blog
  • Home
  • About
Sign in Subscribe

Database

A collection of 3 posts
Setting up Flask SQLAlchemy with PostgreSQL
Web Development

Setting up Flask SQLAlchemy with PostgreSQL

Add these packages to your requirements.txt: flask Flask-SQLAlchemy psycopg2-binary Then install them from your terminal pip install -r requirements.txt In main.py: from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_cors import CORS # database connection parameters DB_HOST = 'localhost' DB_PORT = 5432 DB_
Feb 15, 2023 1 min read
How to create persistent PostgreSQL database with docker-compose
Database

How to create persistent PostgreSQL database with docker-compose

To spin up Postgres on Docker, create docker-compose.yml like so: version: '3.3' services: db: image: postgres:14-alpine # alpine images are lighweight restart: always container_name: db ports: - 5432:5432 # expose default Postgres port for connections environment: # initialize database connection parameters with environment variables. # more info:
Jan 31, 2023
How to set up One2many relationships in Flask SQLAlchemy
Backend

How to set up One2many relationships in Flask SQLAlchemy

class Class(db.Model): id = db.Column(db.Integer, primary_key=True) students = db.relationship('Students', backref='class') def as_dict(self): result = {col.name: getattr(self, col.name) for col in self.__table__.columns} # add students data to result dict result['students'] = [student.
Jan 31, 2023 1 min read
Page 1 of 1
Tim's Blog © 2025
  • Sign up
Powered by Ghost