PostgreSQL侦听/通知功能,通过psycopg2。

psycopg2-pgevents的Python项目详细描述


https://circleci.com/gh/shawalli/psycopg2-pgevents.svg?style=svghttps://coveralls.io/repos/github/shawalli/psycopg2-pgevents/badge.svg?branch=masterhttps://img.shields.io/badge/License-MIT-yellow.svg

这个包使得使用postgresql的notify/listen事件系统变得简单 以一种一致的、令人愉快的方式。

注意,这个项目正式支持Python3.6+。这主要是由于 静态输入。

示例

下面显示了正在运行的包的示例。

假设

  • PostGreSQL server is running locally.
  • default database (^{tt1}$) is available.
  • table exists in database in the public schema with the name ^{tt2}$.
frompsycopg2importconnectfrompsycopg2_pgevents.triggerimportinstall_trigger, \
    install_trigger_function,uninstall_trigger,uninstall_trigger_functionfrompsycopg2_pgevents.eventimportpoll,register_event_channel, \
    unregister_event_channelconnection=connect(dsn='postgres:///postgres')connection.autocommit=Trueinstall_trigger_function(connection)install_trigger(connection,'orders')register_event_channel(connection)try:print('Listening for events...')whileTrue:forevtinpoll(connection):print('New Event: {}'.format(evt))exceptKeyboardInterrupt:print('User exit via Ctrl-C; Shutting down...')unregister_event_channel(connection)uninstall_trigger(connection,'orders')uninstall_trigger_function(connection)print('Shutdown complete.')

故障排除

  • 必须启用连接的autocommit属性,此包才能 操作正确。此要求由PostgreSQL的notify/listen提供 机制。
  • register_event_channel()一起使用的连接必须是 与poll()一起使用,以便接收事件。这是因为 PostgreSQL如何管理“监听”连接。
  • 如果要侦听的表不在公共架构中,则 架构名称必须在^{tt6}中作为关键字参数给定$ 方法。

作者和许可证

由肖恩·沃利斯撰写,在麻省理工学院许可下发行。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
使用applets查询的多人java游戏?   java如何基于字符串生成数组   基于java多边形的路径查找   java如何对多列ArrayList排序   java批处理更新从更新中返回了意外的行数(Spring/Hibernate)   java如何使用SeleniumWebDriver列出<tr>标记内的所有<td>   java如何使用SimpleFlatMapper将前缀为CSV的列别名到映射?   java为什么通过eclipse运行/调试TomCat时会出现ClassNotFoundException   java Android滚动视图上次视图未显示内部线性布局   替换字符串中不带空格的字符序列   调用方法时Java Swing GUI冻结   java是否允许/建议重用收集器?   在同步方法中使用java hashmap迭代器时   在java XMLDecoder XMLEncoder中写入XMLdatabase   java I无法在活动的片段中填充recyclerview   java Jitsi在调用过程中播放WAV文件如果可能,与音频混合   java JPA为什么我看到DB中每行有两个实体实例?