For some reason, in the qiita area, sqlalchemy is an option (561 searches, 161 tags), but there are others, right? Naturally there was.
Both are queries and are characterized by a fairly special description. At first glance, I don't know which one works, python / DB. Am I influenced by linq?
coleifer/peewee: a small, expressive orm -- supports postgresql, mysql and sqlite peewee — peewee 3.13.3 documentation
from peewee import *
import datetime
db = SqliteDatabase('my_database.db')
class BaseModel(Model):
class Meta:
database = db
class User(BaseModel):
username = CharField(unique=True)
class Tweet(BaseModel):
user = ForeignKeyField(User, backref='tweets')
message = TextField()
created_date = DateTimeField(default=datetime.datetime.now)
is_published = BooleanField(default=True)
query = (Facility
.select(Facility.facid, Facility.name, Facility.membercost,
Facility.monthlymaintenance)
.where(
(Facility.membercost > 0) &
(Facility.membercost < (Facility.monthlymaintenance / 50))))
Some outside
-Python Library: Pony ORM -Life with Python -Database operation using Python ORM Pony -Symfoware
A very characteristic and confusing part is that it accepts the python3 generator syntax directly in the query, and if you define an n: m relation, it will create an intermediate table without permission.
from pony.orm import *
db = Database()
class MyEntity(db.Entity):
attr1 = Required(str)
select(c for c in Customer if sum(c.orders.price) > 1000)
SELECT "c"."id"
FROM "customer" "c"
LEFT JOIN "order" "order-1"
ON "c"."id" = "order-1"."customer"
GROUP BY "c"."id"
HAVING coalesce(SUM("order-1"."total_price"), 0) > 1000
Recommended Posts