-
Notifications
You must be signed in to change notification settings - Fork 0
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
10 changed files
with
111 additions
and
94 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub mod adbc; | ||
pub mod file; | ||
pub mod memory; | ||
|
||
|
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
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,2 @@ | ||
pub mod postgresql; | ||
pub mod server; |
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,17 @@ | ||
use async_trait::async_trait; | ||
use pgwire::{ | ||
api::{query::SimpleQueryHandler, results::Response, ClientInfo}, | ||
error::PgWireResult, | ||
}; | ||
|
||
pub struct PostgresqlHandler; | ||
|
||
#[async_trait] | ||
impl SimpleQueryHandler for PostgresqlHandler { | ||
async fn do_query<'a, C>(&self, _client: &mut C, sql: &'a str) -> PgWireResult<Vec<Response<'a>>> | ||
where | ||
C: ClientInfo + Unpin + Send + Sync, | ||
{ | ||
todo!("Implement PostgresqlHandler::do_query()") | ||
} | ||
} |
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,5 @@ | ||
mod handler; | ||
mod server; | ||
|
||
pub use server::PostgresqlServer; | ||
pub use handler::PostgresqlHandler; |
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,77 @@ | ||
use crate::error::Result; | ||
use log::error; | ||
use pgwire::api::MakeHandler; | ||
use pgwire::api::{auth::noop::NoopStartupHandler, query::PlaceholderExtendedQueryHandler, StatelessMakeHandler}; | ||
use std::{net::SocketAddr, sync::Arc}; | ||
|
||
use super::PostgresqlHandler; | ||
|
||
pub struct PostgresqlServer { | ||
addr: SocketAddr, | ||
} | ||
|
||
impl PostgresqlServer { | ||
pub fn new(addr: SocketAddr) -> Self { | ||
PostgresqlServer { addr } | ||
} | ||
} | ||
|
||
impl PostgresqlServer { | ||
pub async fn start(&self) -> Result<()> { | ||
tokio::spawn(Self::listen(self.addr)); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn shutdown(&self) -> Result<()> { | ||
todo!("Implement PostgresqlServer::shutdown()") | ||
} | ||
|
||
async fn listen(addr: SocketAddr) { | ||
let listener = tokio::net::TcpListener::bind(addr) | ||
.await | ||
.unwrap_or_else(|e| panic!("PostgreSQL Server bind fail. err: {}", e)); | ||
|
||
let authenticator = Arc::new(StatelessMakeHandler::new(Arc::new(NoopStartupHandler))); | ||
let processor = Arc::new(StatelessMakeHandler::new(Arc::new(PostgresqlHandler))); | ||
let placeholder = Arc::new(StatelessMakeHandler::new(Arc::new(PlaceholderExtendedQueryHandler))); | ||
|
||
loop { | ||
tokio::select! { | ||
peer = listener.accept() => { | ||
match peer { | ||
Ok((socket, _)) => { | ||
tokio::spawn(pgwire::tokio::process_socket( | ||
socket, | ||
None, | ||
authenticator.make(), | ||
processor.make(), | ||
placeholder.make(), | ||
)); | ||
} | ||
Err(e) => { | ||
error!("PostgreSQL Server accept new connection fail. err: {}", e); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use std::net::SocketAddr; | ||
use std::str::FromStr; | ||
|
||
#[tokio::test] | ||
async fn test_postgresql_server() { | ||
let addr = SocketAddr::from_str("127.0.0.1:5434").unwrap(); | ||
let server = PostgresqlServer::new(addr); | ||
server.start().await.unwrap(); | ||
|
||
// wait | ||
tokio::time::sleep(tokio::time::Duration::from_secs(10000000)).await; | ||
} | ||
} |
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,5 @@ | ||
use crate::server::postgresql; | ||
|
||
pub struct Server { | ||
postgres: postgresql::PostgresqlServer, | ||
} |