Skip to content

brent-hoover/tornpsql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tornpsql Build Status Version

pip install tornpsql

Forked/ported from bdarnell/torndb which is build to support MySQL

Connect and Query

# Method 1
import tornpsql
db = tornpsql.Connection("postgres://postgres-user:postgres-password@127.0.0.1:5432/postgres-db")
results = db.query("select column from mytable")
# Method 2
import tornpsql
db = tornpsql.Connection("127.0.0.1", "database", "postgres", "postgres-user", 5432)
results = db.query("select column from mytable")

PubSub

db = tornpsql.Connection()
pubsub = db.pubsub()
pubsub.subscribe( ("channel_1", ) )
for notify in pubsub.listen():
    print notify.pid, notify.channel, notify.payload

Via Threading

class PubSubThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.db = tornpsql.Connection()
        self.pubsub = self.db.pubsub()
        self.pubsub.subscribe( ("channel_1", "channel_2") )

    def run(self):
        for notify in self.pubsub.listen():
            print notify.pid, notify.channel, notify.payload


pubsub = PubSubThread()

About

Simple PostgreSQL wrapper

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors