You've already forked OpenIntegrations
mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2025-08-10 22:41:43 +02:00
PG: JSON и JSONB
This commit is contained in:
2
src/addins/postgres/Cargo.lock
generated
2
src/addins/postgres/Cargo.lock
generated
@@ -506,6 +506,8 @@ dependencies = [
|
||||
"bytes",
|
||||
"fallible-iterator",
|
||||
"postgres-protocol",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@@ -15,7 +15,7 @@ opt-level = "z"
|
||||
|
||||
[dependencies]
|
||||
addin1c = "0.5.0"
|
||||
postgres = { version = "0.19.9"}
|
||||
postgres = { version = "0.19.9", features = ["with-serde_json-1"]}
|
||||
serde_json = "1.0"
|
||||
base64 = "0.22.1"
|
||||
chrono = "0.4.39"
|
Binary file not shown.
@@ -159,6 +159,15 @@ fn process_object(object: &Map<String, Value>) -> Result<Box<dyn ToSql + Sync>,
|
||||
.and_then(|s| s.parse::<IpAddr>().ok())
|
||||
.map(|ip| Box::new(ip) as Box<dyn ToSql + Sync>)
|
||||
.ok_or_else(|| "Invalid value for INET".to_string()),
|
||||
"JSON" | "JSONB" => {
|
||||
if value.is_object() || value.is_array() {
|
||||
Ok(Box::new(value.to_string()) as Box<dyn ToSql + Sync>)
|
||||
} else if value.is_string() {
|
||||
Ok(Box::new(value.as_str().unwrap().to_string()) as Box<dyn ToSql + Sync>)
|
||||
} else {
|
||||
Err("Invalid value for JSON/JSONB: must be an object, array, or string".to_string())
|
||||
}
|
||||
}
|
||||
_ => Err(format!("Unsupported type: {}", key)),
|
||||
}
|
||||
}
|
||||
@@ -238,6 +247,11 @@ fn rows_to_json(rows: Vec<postgres::Row>) -> String {
|
||||
"inet" => row.get::<_, Option<IpAddr>>(column_name)
|
||||
.map(|ip| Value::String(ip.to_string()))
|
||||
.unwrap_or(Value::Null),
|
||||
"json" | "jsonb" => {
|
||||
row.get::<_, Option<String>>(column_name)
|
||||
.and_then(|s| serde_json::from_str(&s).ok())
|
||||
.unwrap_or(Value::Null)
|
||||
},
|
||||
_ => Value::Null,
|
||||
};
|
||||
|
||||
|
BIN
src/en/OInt/addins/OPI_PostgreSQL.zip
vendored
BIN
src/en/OInt/addins/OPI_PostgreSQL.zip
vendored
Binary file not shown.
Binary file not shown.
BIN
src/ru/OInt/addins/OPI_PostgreSQL.zip
vendored
BIN
src/ru/OInt/addins/OPI_PostgreSQL.zip
vendored
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user