Created
November 16, 2022 03:02
-
-
Save UltiRequiem/ae56f80d1a0a1f4d23fc09e9414f1575 to your computer and use it in GitHub Desktop.
Tutorial π https://youtu.be/1NjbY53DdFE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.8" | |
services: | |
postgres: | |
image: postgres | |
container_name: postgres | |
restart: always | |
environment: | |
POSTGRES_USER: root | |
POSTGRES_PASSWORD: root | |
POSTRGRES_DB: root | |
ports: | |
- "5432:5432" | |
pgadmin: | |
container_name: pgadmin | |
image: dpage/pgadmin4 | |
restart: always | |
environment: | |
PGADMIN_DEFAULT_EMAIL: [email protected] | |
PGADMIN_DEFAULT_PASSWORD: root | |
ports: | |
- "5050:80" | |
depends_on: | |
- postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import psycopg2 | |
import faker | |
connection = psycopg2.connect( | |
host="172.28.0.2", database="root", user="root", password="root" | |
) | |
cursor = connection.cursor() | |
def ensure_person_table_exists(): | |
create_person_table_query = """ | |
CREATE TABLE IF NOT EXISTS person( | |
ID SERIAL PRIMARY KEY, | |
NAME TEXT NOT NULL, | |
ADDRESS TEXT NOT NULL | |
); | |
""" | |
cursor.execute(create_person_table_query) | |
connection.commit() | |
def insert_person(name: str, address: str): | |
insert_query = f"INSERT INTO person (NAME, ADDRESS) VALUES ('{name}','{address}')" | |
cursor.execute(insert_query) | |
connection.commit() | |
ensure_person_table_exists() | |
fake = faker.Faker() | |
for person in range(0, 100): | |
name, address = fake.name(), fake.address() | |
insert_person(name, address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment