简体   繁体   English

Pony orm 连接池

[英]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将 python pony orm 与 postgres(aws rds) 一起使用......使用它来执行原始 sql......所以我围绕 pony 类创建了一个包装类来初始化数据库对象

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.每次调用一个方法来执行原始 sql 查询(下一行)时,都会建立一个新的连接。 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根据 pony orm 文档

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.例如:5 个调用导致 5 个连接。 How can i set max.我怎样才能设置最大。 number of connections?连接数?

As the PonnyORM's documentation says:正如 PonnyORM 的文档所说:

... ...
bind (provider, *args, **kwargs)绑定(提供者,*args,**kwargs)
bind (*args, **kwargs) Bind entities to a database. bind (*args, **kwargs) 将实体绑定到数据库。

Parameters: provider (str) – the name of the database provider.参数: provider (str) – 数据库提供者的名称。 The database provider is a module which resides in the pony.orm.dbproviders package.数据库提供程序是一个位于 pony.orm.dbproviders 包中的模块。 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.在数据库提供程序名称之后,您应该指定将传递给相应 DBAPI 驱动程序的 connect() 方法的参数。 Pony comes with the following providers: “sqlite”, “postgres”, “mysql”, “oracle”, “cockroachdb”. Pony 带有以下提供程序:“sqlite”、“postgres”、“mysql”、“oracle”、“cockroachdb”。 This parameter can be used as a keyword argument as well.此参数也可以用作关键字参数。

args – parameters required by the database driver . args数据库驱动程序所需的参数。
kwargs – parameters required by the database driver . kwargs数据库驱动程序所需的参数。 ... ...

If you are use Psycopg you can check this documentation to use more arguments in your database settings.如果您使用 Psycopg,您可以查看此文档以在数据库设置中使用更多参数。 What I am not sure is if PonyORM considers all options of this package in its library.我不确定的是 PonyORM 是否在其库中考虑了这个包的所有选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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