json bug fixed

This commit is contained in:
filipriec
2025-03-01 14:58:17 +01:00
parent 720d74ddc8
commit 00f0889bed

View File

@@ -1,11 +1,12 @@
// src/table_definition/handlers/post_table_definition.rs
use tonic::Status;
use sqlx::{PgPool, types::Json};
use sqlx::PgPool;
use serde_json::json;
use common::proto::multieko2::table_definition::{PostTableDefinitionRequest, TableDefinitionResponse};
// Validate SQL identifiers
fn is_valid_identifier(s: &str) -> bool {
!s.is_empty() &&
!s.is_empty() &&
s.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') &&
!s.starts_with('_') &&
!s.chars().next().unwrap().is_ascii_digit()
@@ -58,8 +59,8 @@ pub async fn post_table_definition(
VALUES ($1, $2, $3, $4)"#,
"system", // Or get from auth context
&table_name,
Json(&columns),
Json(&indexes)
json!(columns), // Use serde_json::json! to convert Vec<String> to JsonValue
json!(indexes) // Use serde_json::json! to convert Vec<String> to JsonValue
)
.execute(db_pool)
.await
@@ -78,7 +79,8 @@ pub async fn post_table_definition(
.await
.map_err(|e| Status::internal(format!("Table creation failed: {}", e)))?;
for sql in index_sql {
// Iterate over a reference to index_sql to avoid moving it
for sql in &index_sql {
sqlx::query(&sql)
.execute(db_pool)
.await