A minimal ORM for PostgreSQL
Project description
PostgreSQL Python ORM
A minimal Python ORM for interacting with a PostgreSQL database (using psycopg2)
Installation
pip install post-orm
Example
from post_orm import Database, Column, Table, ForeignKey
db = Database(
database="test_database",
user="postgres",
password="1234",
host="localhost",
port="5432",
)
# Create tables
class School(Table):
country = Column(str)
name = Column(str)
class Student(Table):
name = Column(str)
school = ForeignKey(School)
db.create(School)
db.create(Student)
# Save school
school = School(name="Hogwarts", country="England")
db.save(school)
# Save students
harry = Student(name="Harry Potter", school=school)
ron = Student(name="Ron Weasley", school=school)
db.save([harry, ron])
# Make queries
all_students = db.all(Student)
harrys_school = db.query(Student, name="Harry Potter", limit=1).school # use limit=1 to return a single object.
hogwarts = db.query(School, country="Eng%", limit=1) # use % for wildcard search.
assert harrys_school.country == hogwarts.country
Run tests in Docker
Prepare a test-databse
docker run --rm -P -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD="1234" --name pg postgres:alpine
psql postgresql://postgres:1234@localhost:5432/postgres
CREATE DATABASE test_database;
Run tests
python -m pytest .
This project was heavily inspiered by the SQLite ORM in this course on testdriven.io
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
post_orm-0.0.2.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file post_orm-0.0.2.tar.gz
.
File metadata
- Download URL: post_orm-0.0.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1471ab79a2e020b0f7440086ed85bdd58e1cfb638ea84f854c88211261f80453 |
|
MD5 | 0d7dd1c9f80ea8786945a682de55ec89 |
|
BLAKE2b-256 | 46ac672a01c71e55209190ba3c83bb6aec5354148a73d68cd4d4cdd092b36d62 |
File details
Details for the file post_orm-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: post_orm-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f9d0818c7ad0077dc32a1b2ffdc74e98a34da8ac5c9b4aa524c1656c57dd884 |
|
MD5 | d89823a8cf59bc3c1d2f21d86a1d1acf |
|
BLAKE2b-256 | 87cbe41a05148f634273f4707e9c7cc0776d1b62131937b20d993d72476ff15f |