mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-14 09:12:57 +00:00
* feat: add pg and mysql server_address options * feat: start pg and mysql server(standalone) * feat: start pg and mysql in distribute * feat: finally get there, specify postgres sqlness * feat: support mysql sqlness * fix: license * fix: remove unused import * fix: toml * fix: clippy * refactor: BeginProtocolInterceptorFactory to ProtocolInterceptorFactory * fix: sqlness pg connect * fix: clippy * Apply suggestions from code review Co-authored-by: Yingwen <realevenyag@gmail.com> * fix: rustfmt * fix: reconnect pg and mysql when restart * test: add mysql related sqlness * fix: wait for start while restarting * fix: clippy * fix: cargo lock conflict fix: Cargo.lock conflict * fix: usage of '@@tx_isolation' in sqlness * fix: typos * feat: retry with backoff when create client * fix: use millisecond rather than microseconds in backoff --------- Co-authored-by: Yingwen <realevenyag@gmail.com>
49 lines
1.6 KiB
Rust
49 lines
1.6 KiB
Rust
// Copyright 2023 Greptime Team
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use sqlness::interceptor::{Interceptor, InterceptorFactory, InterceptorRef};
|
|
use sqlness::SqlnessError;
|
|
|
|
pub const PROTOCOL_KEY: &str = "protocol";
|
|
pub const POSTGRES: &str = "postgres";
|
|
pub const MYSQL: &str = "mysql";
|
|
pub const PREFIX: &str = "PROTOCOL";
|
|
|
|
pub struct ProtocolInterceptor {
|
|
protocol: String,
|
|
}
|
|
|
|
impl Interceptor for ProtocolInterceptor {
|
|
fn before_execute(&self, _: &mut Vec<String>, context: &mut sqlness::QueryContext) {
|
|
context
|
|
.context
|
|
.insert(PROTOCOL_KEY.to_string(), self.protocol.clone());
|
|
}
|
|
}
|
|
|
|
pub struct ProtocolInterceptorFactory;
|
|
|
|
impl InterceptorFactory for ProtocolInterceptorFactory {
|
|
fn try_new(&self, ctx: &str) -> Result<InterceptorRef, SqlnessError> {
|
|
let protocol = ctx.to_lowercase();
|
|
match protocol.as_str() {
|
|
POSTGRES | MYSQL => Ok(Box::new(ProtocolInterceptor { protocol })),
|
|
_ => Err(SqlnessError::InvalidContext {
|
|
prefix: PREFIX.to_string(),
|
|
msg: format!("Unsupported protocol: {}", ctx),
|
|
}),
|
|
}
|
|
}
|
|
}
|