Skip to main content

PonyORM Database object Facade

Project description

Latest Version Apache 2.0 STARS

PonyORM Database object Facade. The package encapsulates the names of the parameters used in the low-level modules.

Русская документация

Installation

pip install pony-database-facade

Constructor

The DatabaseFacade constructor and the bind method takes the following arguments:

provider

The name of the database provider. One of the list: sqlite, mysql, postgres or oracle. By default is sqlite.

dbname

The name of the database. If you are using SQLite, the name of the file in which SQLite will store the data and by default is :memory:.

host

Name of host to connect to. By default is localhost.

port

TCP port of database server. By default is standard port.

user

User to authenticate as. By default is None.

password

Password to authenticate with. By default is None.

charset (MySQL only)

By default is utf8.

create_db (SQLite only)

Try to create the database if such filename doesn’t exists. By default is True.

*args

parameters required by the database driver.

**kwargs

parameters required by the database driver.

# SQLite in memory
db = DatabaseFacade()

# MySQL, localhost, no user, no password, used database blog
db = DatabaseFacade('mysql', dbname='blog')
db = DatabaseFacade(provider='mysql', dbname='blog')

# PostgreSQL
db = DatabaseFacade()
db.bind('postgres',
        host='my.vps.com',
        user='anyone',
        password='anykey',
        dbname='blog')

Connection

To connect to the database, use the connect method. This method takes the same arguments as generate_mapping, but the default for create_tables is True. This method also calls the bind method.

db = DatabaseFacade()
db.connect()

Full example

from pony.orm import Required, db_session, show
from pony_database_facade import DatabaseFacade


db = DatabaseFacade()


class Person(db.Entity):
    username = Required(str, 50)


db.connect()

with db_session:
    person_1 = Person(username='Linus')

show(person_1)

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

pony-database-facade-2.0.1.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file pony-database-facade-2.0.1.tar.gz.

File metadata

File hashes

Hashes for pony-database-facade-2.0.1.tar.gz
Algorithm Hash digest
SHA256 9845afdaa7f2e5c01e5de92a5906f497335bac5e2d5e38e0a0015de271ca4b88
MD5 cb042c4cefa434072905d7579fc8c1e4
BLAKE2b-256 7e4b56e48e4809483da3ea144a95f9e1b470a44b47d55f1f9314cc3fb5114f15

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page