Closed kamelzcs closed 9 years ago
I found the Manual connection management
part.
Thanks for your great library!
Yes, manual connection management is the way to go.
Glad you liked Momoko.
On Fri, Nov 28, 2014, 12:18 kamelzcs notifications@github.com wrote:
Closed #85 https://github.com/FSX/momoko/issues/85.
— Reply to this email directly or view it on GitHub https://github.com/FSX/momoko/issues/85#event-199853606.
FYI you can also do this in one query with INSERT ... RETURNING
. Here is an example:
import logging
from tornado import ioloop, options
import momoko
options.parse_command_line()
loop = ioloop.IOLoop.instance()
db = momoko.Pool(dsn=DSN, size=3)
def res(cursor, error):
logging.info("inserted: %r", cursor.fetchone())
def test1():
db.execute('INSERT INTO binarydata (datetimeread) VALUES (now()) RETURNING id', callback=res)
pc = ioloop.PeriodicCallback(test1, 1000)
pc.start()
loop.start()
For example, after
insert
a row, I want to get itsid
, using theSELECT CURRVAL('member_id_seq')
, which would require the second query be in the same connection with the first one. But I dont know how to implement that using momoko.I tried:
1.
it will give such error:
I think the reason is the second query is not the same connection as the first
insert
commands.2.
It will give such error:
The
cursor.execute
is asynchronous, the result is not available when thefetch*
method is called.I tried to use
It would give the
Eventhough I know it would be fine to use the
insert into ... returning id
command on this specific target, but what is the general way to do multiple queries on the same connection?