added realm to jspg processing
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
use crate::database::Database;
|
||||
use crate::database::realm::SchemaRealm;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Compiler<'a> {
|
||||
@ -24,13 +25,18 @@ pub struct Node<'a> {
|
||||
impl<'a> Compiler<'a> {
|
||||
/// Compiles a JSON schema into a nested PostgreSQL query returning JSONB
|
||||
pub fn compile(&self, schema_id: &str, filter_keys: &[String]) -> Result<String, String> {
|
||||
let realm = if schema_id.ends_with(".request") || schema_id.ends_with(".response") {
|
||||
SchemaRealm::Punc
|
||||
} else {
|
||||
SchemaRealm::Type
|
||||
};
|
||||
|
||||
let schema = self
|
||||
.db
|
||||
.schemas
|
||||
.get(schema_id)
|
||||
.get_scoped_schema(realm, schema_id)
|
||||
.ok_or_else(|| format!("Schema not found: {}", schema_id))?;
|
||||
|
||||
let target_schema = std::sync::Arc::clone(schema);
|
||||
let target_schema = schema;
|
||||
|
||||
let mut compiler = Compiler {
|
||||
db: &self.db,
|
||||
@ -151,9 +157,9 @@ impl<'a> Compiler<'a> {
|
||||
if let Some(crate::database::object::SchemaTypeOrArray::Single(t)) = &node.schema.obj.type_ {
|
||||
if !crate::database::object::is_primitive_type(t) {
|
||||
// If it's just an ad-hoc struct ref, we should resolve it
|
||||
if let Some(target_schema) = self.db.schemas.get(t) {
|
||||
if let Some(target_schema) = self.db.get_scoped_schema(SchemaRealm::Type, t) {
|
||||
let mut ref_node = node.clone();
|
||||
ref_node.schema = Arc::clone(target_schema);
|
||||
ref_node.schema = target_schema.clone();
|
||||
ref_node.schema_id = Some(t.clone());
|
||||
return self.compile_node(ref_node);
|
||||
}
|
||||
@ -306,9 +312,9 @@ impl<'a> Compiler<'a> {
|
||||
|
||||
for (disc_val, (idx_opt, target_id_opt)) in options {
|
||||
if let Some(target_id) = target_id_opt {
|
||||
if let Some(target_schema) = self.db.schemas.get(target_id) {
|
||||
if let Some(target_schema) = self.db.get_scoped_schema(SchemaRealm::Type, target_id) {
|
||||
let mut child_node = node.clone();
|
||||
child_node.schema = Arc::clone(target_schema);
|
||||
child_node.schema = target_schema.clone();
|
||||
child_node.schema_id = Some(target_id.clone());
|
||||
child_node.is_polymorphic_branch = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user