feat: add QuestDB support
Thanks @ptma!
This commit is contained in:
1 parent
0ae720d950
commit
1afc271c18
51 files changed
+633
-46
No files matched your search
@@ -41,7 +41,8 @@ pub fn quote_table_identifier(database_type: Option<DatabaseType>, name: &str) -
|
||||
| DatabaseType::Databend
|
||||
| DatabaseType::Tdengine
|
||||
| DatabaseType::Access
|
||||
| DatabaseType::Bigquery,
|
||||
| DatabaseType::Bigquery
|
||||
| DatabaseType::Questdb,
|
||||
) => {
|
||||
format!("`{}`", name.replace('`', "``"))
|
||||
}
|
||||
@@ -69,7 +70,8 @@ pub(crate) fn quote_transfer_identifier(name: &str, database_type: &DatabaseType
|
||||
| DatabaseType::ClickHouse
|
||||
| DatabaseType::Doris
|
||||
| DatabaseType::StarRocks
|
||||
| DatabaseType::Hive => format!("`{}`", name.replace('`', "``")),
|
||||
| DatabaseType::Hive
|
||||
| DatabaseType::Questdb => format!("`{}`", name.replace('`', "``")),
|
||||
DatabaseType::SqlServer => format!("[{}]", name.replace(']', "]]")),
|
||||
_ => format!("\"{}\"", name.replace('\"', "\"\"")),
|
||||
}
|
||||
@@ -77,7 +79,8 @@ pub(crate) fn quote_transfer_identifier(name: &str, database_type: &DatabaseType
|
||||
|
||||
pub(crate) fn qualified_transfer_table(table_name: &str, schema: &str, database_type: &DatabaseType) -> String {
|
||||
let table = quote_transfer_identifier(table_name, database_type);
|
||||
if schema.is_empty() || matches!(database_type, DatabaseType::Mysql | DatabaseType::MongoDb) {
|
||||
if schema.is_empty() || matches!(database_type, DatabaseType::Mysql | DatabaseType::MongoDb | DatabaseType::Questdb)
|
||||
{
|
||||
table
|
||||
} else {
|
||||
format!("{}.{}", quote_transfer_identifier(schema, database_type), table)
|
||||
|
||||
@@ -110,6 +110,17 @@ pub fn build_table_data_select_sql(options: TableDataSelectSqlOptions) -> String
|
||||
);
|
||||
}
|
||||
|
||||
if database_type == Some(DatabaseType::Questdb) {
|
||||
return build_questdb_table_select_sql(
|
||||
&table_alias,
|
||||
&where_clause,
|
||||
&order,
|
||||
&options.columns,
|
||||
limit,
|
||||
options.offset.unwrap_or(0),
|
||||
);
|
||||
}
|
||||
|
||||
let offset =
|
||||
options.offset.filter(|offset| *offset > 0).map(|offset| format!(" OFFSET {offset}")).unwrap_or_default();
|
||||
format!("SELECT {select_columns} FROM {table_alias}{where_clause}{order} LIMIT {limit}{offset};")
|
||||
@@ -332,3 +343,27 @@ pub(super) fn build_neo4j_table_select_sql(options: &TableDataSelectSqlOptions,
|
||||
let skip = options.offset.filter(|offset| *offset > 0).map(|offset| format!(" SKIP {offset}")).unwrap_or_default();
|
||||
format!("MATCH (n:{label}){where_clause} RETURN {returns}{order}{skip} LIMIT {limit};")
|
||||
}
|
||||
|
||||
pub(super) fn build_questdb_table_select_sql(
|
||||
table: &str,
|
||||
where_clause: &str,
|
||||
order_by: &str,
|
||||
columns: &[String],
|
||||
limit: usize,
|
||||
offset: usize,
|
||||
) -> String {
|
||||
let columns_sql = if columns.is_empty() {
|
||||
"*".to_string()
|
||||
} else {
|
||||
columns
|
||||
.iter()
|
||||
.map(|column| quote_table_identifier(Some(DatabaseType::Questdb), column))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
};
|
||||
if offset == 0 {
|
||||
return format!("SELECT {columns_sql} FROM {table}{where_clause}{order_by} LIMIT {limit}");
|
||||
}
|
||||
let upper_bound = offset + limit;
|
||||
return format!("SELECT {columns_sql} FROM {table}{where_clause}{order_by} LIMIT {offset}, {upper_bound}");
|
||||
}
|
||||
Reference in new issue
Block a user