-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expose procedures as part of the schema endpoint #198
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,7 @@ pub async fn get_schema( | |
.native_queries | ||
.0 | ||
.iter() | ||
.filter(|(_, info)| !info.is_procedure) | ||
.map(|(name, info)| models::CollectionInfo { | ||
name: name.clone(), | ||
description: info.description.clone(), | ||
|
@@ -207,9 +208,34 @@ pub async fn get_schema( | |
let mut object_types = table_types; | ||
object_types.extend(native_queries_types); | ||
|
||
let procedures: Vec<models::ProcedureInfo> = metadata | ||
.native_queries | ||
.0 | ||
.iter() | ||
.filter(|(_, info)| info.is_procedure) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only include procedures in the procedures list. |
||
.map(|(name, info)| models::ProcedureInfo { | ||
name: name.clone(), | ||
description: info.description.clone(), | ||
arguments: info | ||
.arguments | ||
.iter() | ||
.map(|(name, column_info)| { | ||
( | ||
name.clone(), | ||
models::ArgumentInfo { | ||
description: column_info.description.clone(), | ||
argument_type: column_to_type(column_info), | ||
}, | ||
) | ||
}) | ||
.collect(), | ||
result_type: models::Type::Named { name: name.clone() }, | ||
}) | ||
.collect(); | ||
|
||
Ok(models::SchemaResponse { | ||
collections, | ||
procedures: vec![], | ||
procedures, | ||
functions: vec![], | ||
object_types, | ||
scalar_types, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,21 @@ pub struct NativeQueries(pub BTreeMap<String, NativeQueryInfo>); | |
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct NativeQueryInfo { | ||
/** SQL expression to use for the Native Query. We can interpolate values using `{{variable_name}}` syntax, such as `SELECT * FROM authors WHERE name = {{author_name}}` */ | ||
/// SQL expression to use for the Native Query. | ||
/// We can interpolate values using `{{variable_name}}` syntax, | ||
/// such as `SELECT * FROM authors WHERE name = {{author_name}}` | ||
pub sql: NativeQuerySql, | ||
/** Columns returned by the Native Query */ | ||
/// Columns returned by the Native Query | ||
pub columns: BTreeMap<String, ColumnInfo>, | ||
#[serde(default)] | ||
/** Names and types of arguments that can be passed to this Native Query */ | ||
/// Names and types of arguments that can be passed to this Native Query | ||
pub arguments: BTreeMap<String, ColumnInfo>, | ||
#[serde(default)] | ||
pub description: Option<String>, | ||
/// True if this native query mutates the database | ||
#[serde(skip_serializing_if = "std::ops::Not::not")] | ||
#[serde(default)] | ||
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Versioning considerations:
I don't think this is an issue just now. I'm mostly writing this comment to practise being dilligent wrt versioning. |
||
pub is_procedure: bool, | ||
} | ||
|
||
/// A part of a Native Query text, either raw text or a parameter. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't include procedures in the collections list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use
Iterator::partition
to filter the native queries once.