-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
12,055 additions
and
3,079 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from edb.server.pgcon.rust_transport import create_postgres_connection | ||
import asyncio | ||
import time | ||
|
||
class MyProtocol(asyncio.Protocol): | ||
def __init__(self): | ||
self.closed = asyncio.Future() | ||
|
||
def connection_made(self, transport): | ||
print(f"Connection made: {transport.connection}") | ||
self.transport = transport | ||
|
||
def data_received(self, data): | ||
print(f"Received: {data}") | ||
self.transport.close() | ||
|
||
def connection_lost(self, exc): | ||
print(f"Connection lost: {exc}") | ||
self.closed.set_result(None) | ||
|
||
async def main(): | ||
now = time.perf_counter_ns() | ||
transport, protocol = await create_postgres_connection( | ||
"postgres://user:password@localhost/postgres", | ||
lambda: MyProtocol(), | ||
state_change_callback=lambda state: print(f"Connection: {state.name}")) | ||
print(f"Connection time: {(time.perf_counter_ns() - now) // 1000}µs") | ||
print(f"Connected: {transport}") | ||
print(f"Peer: {transport.get_extra_info('peername')}") | ||
print(f"Cipher: {transport.get_extra_info('cipher')}") | ||
|
||
# Send a simple query message | ||
query = b'SELECT version();\0' | ||
message = b'Q' + (len(query) + 4).to_bytes(4, 'big') + query | ||
transport.write(message) | ||
|
||
await protocol.closed | ||
|
||
asyncio.run(main()) |
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
Oops, something went wrong.