简体   繁体   中英

Pony orm connection pooling

using python pony orm with postgres(aws rds)... using it to execute raw sql ... so i created a wrapper class around pony classes to initialize database object

self.db = Database()
self.db.bind(provider="postgres", user=self.username, password=self.password,
                host=self.hostname, database=self.database)

every time a method is called to execute raw sql query(below line), a new connection is made. when does connection pooling kick in

self.db.execute(query, query_args)

or is there a way to set connection pooling params.

As per pony orm docs

Connection pool . There is no need to keep track of database connections. You have the connection when you need it and when you have finished your transaction the connection will be returned to the pool.

but I see the connections are always opened everytime a select call is made. eg: 5 calls results in 5 connections. How can i set max. number of connections?

As the PonnyORM's documentation says:

...
bind (provider, *args, **kwargs)
bind (*args, **kwargs) Bind entities to a database.

Parameters: provider (str) – the name of the database provider. The database provider is a module which resides in the pony.orm.dbproviders package. It knows how to work with a particular database. After the database provider name you should specify parameters which will be passed to the connect() method of the corresponding DBAPI driver. Pony comes with the following providers: “sqlite”, “postgres”, “mysql”, “oracle”, “cockroachdb”. This parameter can be used as a keyword argument as well.

args – parameters required by the database driver .
kwargs – parameters required by the database driver . ...

If you are use Psycopg you can check this documentation to use more arguments in your database settings. What I am not sure is if PonyORM considers all options of this package in its library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM