- Peewee - Discussion
- Peewee - Useful Resources
- Peewee - Quick Guide
- Peewee - Using CockroachDB
- Peewee - PostgreSQL & MySQL Extensions
- Peewee - SQLite Extensions
- Peewee - Integration with Web Frameworks
- Peewee - Query Builder
- Peewee - Database Errors
- Peewee - Atomic Transactions
- Peewee - User defined Operators
- Peewee - Retrieving Row Tuples/Dictionaries
- Peewee - SQL Functions
- Peewee - Counting & Aggregation
- Peewee - Sorting
- Peewee - Subqueries
- Peewee - Relationships & Joins
- Peewee - Connection Management
- Peewee - Defining Database Dynamically
- Peewee - Using PostgreSQL
- Peewee - Using MySQL
- Peewee - Constraints
- Peewee - Create Index
- Peewee - Delete Records
- Peewee - Update Existing Records
- Peewee - Primary & Composite Keys
- Peewee - Filters
- Peewee - Select Records
- Peewee - Insert a New Record
- Peewee - Field Class
- Peewee - Model
- Peewee - Database Class
- Peewee - Overview
- Peewee - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Peewee - PostgreSQL and MySQL Extensions
Additional PostgreSQL functionapty is enabled by helpers which are defined in playhouse.postgres_ext module. This module defines PostgresqlExtDatabase class and provides the following additional field types to be exclusively used for declaration of model to be mapped against PostgreSQL database table.
Features of PostgreSQL Extensions
The features of PostgreSQL Extensions which are supported by Peewee are as follows −
ArrayField field type, for storing arrays.
HStoreField field type, for storing key/value pairs.
IntervalField field type, for storing timedelta objects.
JSONField field type, for storing JSON data.
BinaryJSONField field type for the jsonb JSON data type.
TSVectorField field type, for storing full-text search data.
DateTimeTZField field type, a timezone-aware datetime field.
Additional Postgres-specific features in this module are meant to provide.
hstore support.
server-side cursors.
full-text search.
Postgres hstore is a key:value store that can be embedded in a table as one of the fields of type HStoreField. To enable hstore support, create database instance with register_hstore=True parameter.
db = PostgresqlExtDatabase( mydatabase , register_hstore=True)
Define a model with one HStoreField.
class Vehicles(BaseExtModel): type = CharField() features = HStoreField()
Create a model instance as follows −
v=Vechicle.create(type= Car , specs:{ mfg : Maruti , Fuel : Petrol , model : Alto })
To access hstore values −
obj=Vehicle.get(Vehicle.id=v.id) print (obj.features)
MySQL Extensions
Alternate implementation of MysqlDatabase class is provided by MySQLConnectorDatabase defined in playhouse.mysql_ext module. It uses Python’s DB-API compatible official mysql/python connector.
from playhouse.mysql_ext import MySQLConnectorDatabase db = MySQLConnectorDatabase( mydatabase , host= localhost , user= root , password= )Advertisements