Skip to content

Instantly share code, notes, and snippets.

@RNGKing
Created May 26, 2025 19:15
Show Gist options
  • Save RNGKing/a9c52d048c959b60854058d6cc198589 to your computer and use it in GitHub Desktop.
Save RNGKing/a9c52d048c959b60854058d6cc198589 to your computer and use it in GitHub Desktop.
Poem OpenAPI Question
[derive(Tags)]
pub enum ApiTags{
Query,
}
#[derive(Deserialize, Serialize, Clone)]
#[serde(untagged)]
pub enum ColumnData{
Text(String),
Integer(i64),
Real(f64),
Blob(Vec<u8>),
Null
}
impl Type for ColumnData{
const IS_REQUIRED: bool = true;
type RawValueType = Self;
type RawElementValueType = Self;
fn name() -> Cow<'static, str> {
Cow::Owned("ColumnData".into())
}
fn schema_ref() -> MetaSchemaRef {
Self::schema_ref()
}
fn as_raw_value(&self) -> Option<&Self::RawValueType> {
Some(self)
}
// This is the issue right here! Cannot return a temporary value
fn raw_element_iter<'a>(&'a self) -> Box<dyn Iterator<Item=&'a Self::RawElementValueType> + 'a> {
let output_array = [
ColumnData::Text(String::new()),
ColumnData::Blob(Vec::new()),
ColumnData::Null,
ColumnData::Integer(0),
ColumnData::Real(0.0)].iter().collect::<Vec<&ColumnData>>();
Box::new(output_array.into_iter())
}
}
impl ParseFromJSON for ColumnData{
fn parse_from_json(value: Option<Value>) -> ParseResult<Self> {
todo!()
}
fn parse_from_json_string(s: &str) -> ParseResult<Self> {
todo!()
}
}
impl ToJSON for ColumnData{
fn to_json(&self) -> Option<Value> {
todo!()
}
fn to_json_string(&self) -> String {
todo!()
}
}
#[derive(Serialize,Clone, Object)]
pub struct DataRow{
data: Vec<ColumnData>
}
#[derive(Serialize,Clone, Object)]
pub struct SqlResponse{
#[oai(read_only)]
pub request_id : u64,
pub column_names : Vec<String>,
pub row_data : Vec<DataRow>
}
#[derive(ApiResponse)]
pub enum QueryResponse{
#[oai(status = 200)]
Ok(Json<SqlResponse>),
#[oai(status = 500)]
QueryError
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment