python (3) dominer ORM collection

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?

peewee search 35 tag 8

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))))

ponyorm ← qiita is only here for now

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

python (3) dominer ORM collection
python small story collection
[Python] Sort collection types
python snippet collection with cinema4d
Image Processing Collection in Python
Python
Perform Scala-like collection operations in Python
Generate a first class collection in Python
Automatic collection of stock prices using python
[Python] Sorting collection types as a reference
Scientific Programming Petit Tech Collection in Python