Skip to content

Commit ec4f8e5

Browse files
committed
Complete server implementation with working pgwire handler
1 parent 0b311a0 commit ec4f8e5

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

ROADMAP.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ This stage will implement the query language of ArgusDB.
5454

5555
The goal of this stage will be to connect the internal API for accessing ArgusDB to the Postgres wire protocol so clients can connect to the database.
5656

57-
- [] Create a binary that starts a Postgres server
58-
- [] Receive SQL commands from the Postgres server and execute the queries against ArgusDB
59-
- [] Convert the results of the query into a format they can be passed along to the client
57+
- [x] Create a binary that starts a Postgres server
58+
- [x] Receive SQL commands from the Postgres server and execute the queries against ArgusDB
59+
- [x] Convert the results of the query into a format they can be passed along to the client

src/main.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,37 +100,41 @@ struct ArgusProcessor {
100100
handler: Arc<ArgusHandler>,
101101
}
102102

103-
// ... imports
104-
105-
// Commented out to allow compilation for debugging
106-
/*
107103
impl PgWireServerHandlers for ArgusProcessor {
108-
type StartupHandler = pgwire::api::NoopHandler;
109-
type SimpleQueryHandler = ArgusHandler;
110-
type ExtendedQueryHandler = pgwire::api::NoopHandler;
111-
type ErrorHandler = pgwire::api::NoopHandler;
112-
113-
fn simple_query_handler(&self) -> Arc<Self::SimpleQueryHandler> {
104+
fn simple_query_handler(&self) -> Arc<ArgusHandler> {
114105
self.handler.clone()
115106
}
116107

117-
fn startup_handler(&self) -> Arc<Self::StartupHandler> {
108+
fn startup_handler(&self) -> Arc<pgwire::api::NoopHandler> {
118109
Arc::new(pgwire::api::NoopHandler)
119110
}
120111

121-
fn extended_query_handler(&self) -> Arc<Self::ExtendedQueryHandler> {
112+
fn extended_query_handler(&self) -> Arc<pgwire::api::NoopHandler> {
122113
Arc::new(pgwire::api::NoopHandler)
123114
}
124115

125-
fn error_handler(&self) -> Arc<Self::ErrorHandler> {
116+
fn error_handler(&self) -> Arc<pgwire::api::NoopHandler> {
126117
Arc::new(pgwire::api::NoopHandler)
127118
}
128119
}
129-
*/
130120

131-
// Placeholder main to allow test execution
132121
#[tokio::main]
133122
async fn main() {
134-
println!("Server placeholder");
123+
let db = Arc::new(Mutex::new(DB::new("argus_data")));
124+
let handler = Arc::new(ArgusHandler::new(db));
125+
let processor = Arc::new(ArgusProcessor { handler });
126+
127+
let server_addr = "127.0.0.1:5432";
128+
let listener = TcpListener::bind(server_addr).await.unwrap();
129+
println!("ArgusDB server listening on {}", server_addr);
130+
131+
loop {
132+
let (socket, _) = listener.accept().await.unwrap();
133+
let processor = processor.clone();
134+
135+
tokio::spawn(async move {
136+
process_socket(socket, None, processor).await;
137+
});
138+
}
135139
}
136140

0 commit comments

Comments
 (0)