Skip to content
Snippets Groups Projects
picodata_example.py 764 B
Newer Older
#!/usr/bin/env python3

import asyncio
import asyncpg

async def main():
    conn = await asyncpg.connect('postgresql://admin:T0psecret@localhost:55432')

    await conn.execute('''
        CREATE TABLE "warehouse" (id INTEGER NOT NULL, item TEXT NOT NULL, PRIMARY KEY (id)) USING memtx DISTRIBUTED BY (id) OPTION (TIMEOUT = 3.0);
    ''')
    print("table create")

    res = await conn.execute('DELETE FROM \"warehouse\";')
    print("delete ok: ", res)

    res = await conn.execute('INSERT INTO \"warehouse\" VALUES ($1::int, $2::varchar)', 1, "test")
    print("insert ok", res)

    res = await conn.fetchrow('SELECT * FROM warehouse WHERE id = $1::int', 1)
    print("result: ", res)

    # Close the connection.
    await conn.close()

asyncio.run(main())