-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test copy into table methods for asyncpg
- Loading branch information
1 parent
f55b899
commit a3e8ab3
Showing
3 changed files
with
62 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
__title__ = "asyncdb" | ||
__description__ = "Library for Asynchronous data source connections \ | ||
Collection of asyncio drivers." | ||
__version__ = "2.9.5" | ||
__version__ = "2.9.6" | ||
__author__ = "Jesus Lara" | ||
__author_email__ = "[email protected]" | ||
__license__ = "BSD" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
from asyncdb import AsyncDB, AsyncPool | ||
from asyncdb.meta import asyncORM | ||
from asyncdb.exceptions import NoDataFound, ProviderError, StatementError | ||
|
||
""" | ||
|
@@ -26,7 +25,7 @@ | |
loop = asyncio.get_event_loop() | ||
asyncio.set_event_loop(loop) | ||
|
||
asyncpg_url = "postgres://troc_pgdata:[email protected]:5432/navigator_dev" | ||
asyncpg_url = "postgres://troc_pgdata:[email protected]:5432/navigator" | ||
|
||
pool = AsyncPool("pg", dsn=asyncpg_url, loop=loop) | ||
loop.run_until_complete(pool.connect()) | ||
|
@@ -44,7 +43,7 @@ def adb(): | |
if pool.is_connected(): | ||
#db = asyncio.get_running_loop().run_until_complete(dbpool.acquire()) | ||
db = loop.run_until_complete(pool.acquire()) | ||
return asyncORM(db=db) | ||
return db | ||
|
||
def sharing_token(token): | ||
db = adb() | ||
|
@@ -97,26 +96,28 @@ async def connect(c): | |
result, error = await conn.execute("SET TIMEZONE TO 'America/New_York'") | ||
await t.commit() | ||
# table copy | ||
await c.copy_from_table( | ||
table="stores", | ||
schema="walmart", | ||
columns=["store_id", "store_name"], | ||
output="stores.csv", | ||
) | ||
async with await c.transaction() as t: | ||
await t.copy_from_table( | ||
table="stores", | ||
schema="walmart", | ||
columns=["store_id", "store_name"], | ||
output="stores.csv", | ||
) | ||
# copy from file to table | ||
# TODO: repair error io.UnsupportedOperation: read | ||
# await c.copy_to_table(table = 'stores', schema = 'test', columns = [ 'store_id', 'store_name'], source = '/home/jesuslara/proyectos/navigator-next/stores.csv') | ||
# copy from asyncpg records | ||
# try: | ||
# await c.copy_into_table( | ||
# table="stores", | ||
# schema="test", | ||
# columns=["store_id", "store_name"], | ||
# source=stores, | ||
# ) | ||
# except (StatementError, ProviderError) as err: | ||
# print(str(err)) | ||
# return False | ||
async with await t.transaction() as t: | ||
await t.copy_to_table(table = 'stores', schema = 'test', columns = [ 'store_id', 'store_name'], source = '/home/jesuslara/proyectos/navigator-next/stores.csv') | ||
# copy from asyncpg records | ||
try: | ||
await c.copy_into_table( | ||
table="stores", | ||
schema="test", | ||
columns=["store_id", "store_name"], | ||
source=stores, | ||
) | ||
except (StatementError, ProviderError) as err: | ||
print(str(err)) | ||
return False | ||
|
||
|
||
async def prepared(p): | ||
|
@@ -128,11 +129,9 @@ async def prepared(p): | |
|
||
if __name__ == '__main__': | ||
try: | ||
a = sharing_token('67C1BEE8DDC0BB873930D04FAF16B338F8CB09490571F8901E534937D4EFA8EE33230C435BDA93B7C7CEBA67858C4F70321A0D92201947F13278F495F92DDC0BE5FDFCF0684704C78A3E7BA5133ACADBE2E238F25D568AEC4170EB7A0BE819CE8F758B890855E5445EB22BE52439FA377D00C9E4225BC6DAEDD2DAC084446E7F697BF1CEC129DFB84FA129B7B8881C66EEFD91A0869DAE5D71FD5055FCFF75') | ||
print(a.columns()) | ||
# # test: first with db connected: | ||
e = AsyncDB("pg", dsn=asyncpg_url, loop=loop) | ||
loop.run_until_complete(connect(e)) | ||
# loop.run_until_complete(prepared(e)) | ||
finally: | ||
pool.terminate() | ||
loop.close() |