peewee Documentation
Release 3.5.0We can avoid the extra queries by selecting both Pet and Person, and adding a join. query = (Pet .select(Pet, Person) .join(Person) .where(Pet.animal_type == 'cat')) for pet in query: (continues on next prints: # Kitty Bob # Mittens Jr Herb Let’s get all the pets owned by Bob: for pet in Pet.select().join(Person).where(Person.name == 'Bob'): print(pet.name) # prints: # Kitty # Fido We can do another can avoid this by performing a JOIN and using a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without0 码力 | 282 页 | 1.02 MB | 1 年前3
peewee Documentation
Release 3.5.0avoid the extra queries by selecting both Pet and Person, and adding a join. query = (Pet .select(Pet, Person) .join(Person) .where(Pet.animal_type == 'cat')) for pet in query: prints: # Kitty Bob # Mittens Jr Herb Let’s get all the pets owned by Bob: for pet in Pet.select().join(Person).where(Person.name == 'Bob'): print(pet.name) # prints: # Kitty # Fido We can do another this by performing a JOIN and using a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include0 码力 | 347 页 | 380.80 KB | 1 年前3
peewee Documentation
Release 3.6.0We can avoid the extra queries by selecting both Pet and Person, and adding a join. query = (Pet .select(Pet, Person) .join(Person) (continues on next page) 1.2. Quickstart 7 peewee Documentation, Release prints: # Kitty Bob # Mittens Jr Herb Let’s get all the pets owned by Bob: for pet in Pet.select().join(Person).where(Person.name == 'Bob'): print(pet.name) # prints: # Kitty # Fido We can do another can avoid this by performing a JOIN and using a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people0 码力 | 302 页 | 1.02 MB | 1 年前3
peewee Documentation Release 3.6.0avoid the extra queries by selecting both Pet and Person, and adding a join. query = (Pet .select(Pet, Person) .join(Person) .where(Pet.animal_type == 'cat')) for pet in query: prints: # Kitty Bob # Mittens Jr Herb Let’s get all the pets owned by Bob: for pet in Pet.select().join(Person).where(Person.name == 'Bob'): print(pet.name) # prints: # Kitty # Fido We can do another this by performing a JOIN and using a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include0 码力 | 377 页 | 399.12 KB | 1 年前3
peewee Documentation Release 3.0.0avoid the extra queries by selecting both Pet and Person, and adding a join. query = (Pet .select(Pet, Person) .join(Person) .where(Pet.animal_type == 'cat')) for pet in query: prints: # Kitty Bob # Mittens Jr Herb Let’s get all the pets owned by Bob: for pet in Pet.select().join(Person).where(Person.name == 'Bob'): print pet.name # prints: # Kitty # Fido We can do another this by performing a JOIN and using a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include0 码力 | 319 页 | 361.50 KB | 1 年前3
peewee Documentation
Release 3.3.0We can avoid the extra queries by selecting both Pet and Person, and adding a join. query = (Pet .select(Pet, Person) .join(Person) .where(Pet.animal_type == 'cat')) for pet in query: (continues on next prints: # Kitty Bob # Mittens Jr Herb Let’s get all the pets owned by Bob: for pet in Pet.select().join(Person).where(Person.name == 'Bob'): print(pet.name) # prints: # Kitty # Fido We can do another can avoid this by performing a JOIN and using a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without0 码力 | 280 页 | 1.02 MB | 1 年前3
peewee Documentation
Release 3.4.0We can avoid the extra queries by selecting both Pet and Person, and adding a join. query = (Pet .select(Pet, Person) .join(Person) .where(Pet.animal_type == 'cat')) for pet in query: (continues on next prints: # Kitty Bob # Mittens Jr Herb Let’s get all the pets owned by Bob: for pet in Pet.select().join(Person).where(Person.name == 'Bob'): print(pet.name) # prints: # Kitty # Fido We can do another can avoid this by performing a JOIN and using a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include people without0 码力 | 284 页 | 1.03 MB | 1 年前3
peewee Documentation Release 3.4.0avoid the extra queries by selecting both Pet and Person, and adding a join. query = (Pet .select(Pet, Person) .join(Person) .where(Pet.animal_type == 'cat')) for pet in query: prints: # Kitty Bob # Mittens Jr Herb Let’s get all the pets owned by Bob: for pet in Pet.select().join(Person).where(Person.name == 'Bob'): print(pet.name) # prints: # Kitty # Fido We can do another this by performing a JOIN and using a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include0 码力 | 349 页 | 382.34 KB | 1 年前3
peewee Documentation Release 3.1.0avoid the extra queries by selecting both Pet and Person, and adding a join. query = (Pet .select(Pet, Person) .join(Person) .where(Pet.animal_type == 'cat')) for pet in query: prints: # Kitty Bob # Mittens Jr Herb Let’s get all the pets owned by Bob: for pet in Pet.select().join(Person).where(Person.name == 'Bob'): print(pet.name) # prints: # Kitty # Fido We can do another this by performing a JOIN and using a SQL function to aggregate the results. query = (Person .select(Person, fn.COUNT(Pet.id).alias('pet_count')) .join(Pet, JOIN.LEFT_OUTER) # include0 码力 | 332 页 | 370.77 KB | 1 年前3
peewee Documentation Release 2.10.2the extra queries by selecting both Pet and Person, and adding a join. >>> query = (Pet ... .select(Pet, Person) ... .join(Person) ... .where(Pet.animal_type == 'cat')) >>> for name ... Kitty Bob Mittens Jr Herb Let’s get all the pets owned by Bob: >>> for pet in Pet.select().join(Person).where(Person.name == 'Bob'): ... print pet.name ... Kitty Fido We can do another cool Once again we’ve run into a classic example of N+1 query behavior. We can avoid this by performing a JOIN and aggregating the records: >>> subquery = Pet.select(fn.COUNT(Pet.id)).where(Pet.owner == Person0 码力 | 275 页 | 276.96 KB | 1 年前3
共 16 条
- 1
- 2













