all flow commands working, extension compiled
This commit is contained in:
15
src/lib.rs
15
src/lib.rs
@ -1,24 +1,25 @@
|
||||
use pgrx::*;
|
||||
use jsonschema::{JSONSchema, Draft};
|
||||
use serde_json::{json, Value};
|
||||
use jsonschema::{Draft, Validator};
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::RwLock;
|
||||
use lazy_static::lazy_static;
|
||||
use jsonschema;
|
||||
|
||||
pg_module_magic!();
|
||||
|
||||
// Global, thread-safe schema cache
|
||||
// Global, thread-safe schema cache using the correct Validator type
|
||||
lazy_static! {
|
||||
static ref SCHEMA_CACHE: RwLock<HashMap<String, JSONSchema>> = RwLock::new(HashMap::new());
|
||||
static ref SCHEMA_CACHE: RwLock<HashMap<String, Validator>> = RwLock::new(HashMap::new());
|
||||
}
|
||||
|
||||
// Cache a schema explicitly with a provided ID
|
||||
#[pg_extern(immutable, strict, parallel_safe)]
|
||||
fn cache_schema(schema_id: &str, schema: JsonB) -> bool {
|
||||
match JSONSchema::options()
|
||||
match jsonschema::options()
|
||||
.with_draft(Draft::Draft7)
|
||||
.should_validate_formats(true)
|
||||
.compile(&schema.0)
|
||||
.build(&schema.0)
|
||||
{
|
||||
Ok(compiled) => {
|
||||
SCHEMA_CACHE.write().unwrap().insert(schema_id.to_string(), compiled);
|
||||
@ -41,7 +42,7 @@ fn schema_cached(schema_id: &str) -> bool {
|
||||
#[pg_extern(immutable, strict, parallel_safe)]
|
||||
fn validate_schema(schema_id: &str, instance: JsonB) -> JsonB {
|
||||
let cache = SCHEMA_CACHE.read().unwrap();
|
||||
let compiled_schema = match cache.get(schema_id) {
|
||||
let compiled_schema: &Validator = match cache.get(schema_id) {
|
||||
Some(schema) => schema,
|
||||
None => {
|
||||
return JsonB(json!({
|
||||
|
||||
Reference in New Issue
Block a user