Skip to content

Commit

Permalink
feat: mark GUC prefix reserved (#599)
Browse files Browse the repository at this point in the history
Signed-off-by: usamoi <[email protected]>
  • Loading branch information
usamoi authored Sep 24, 2024
1 parent 64c5a7d commit b3d3243
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
18 changes: 15 additions & 3 deletions src/gucs/embedding.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use super::guc_string_parse;
use embedding::OpenAIOptions;
use pgrx::guc::{GucContext, GucFlags, GucRegistry, GucSetting};
use std::ffi::CStr;

pub fn openai_options() -> OpenAIOptions {
let base_url = guc_string_parse(&OPENAI_BASE_URL, "vectors.openai_base_url");
let api_key = guc_string_parse(&OPENAI_API_KEY, "vectors.openai_api_key");
use crate::error::*;
use pgrx::guc::GucSetting;
use std::ffi::CStr;
fn parse(target: &'static GucSetting<Option<&'static CStr>>, name: &'static str) -> String {
let value = match target.get() {
Some(s) => s,
None => bad_guc_literal(name, "should not be `NULL`"),
};
match value.to_str() {
Ok(s) => s.to_string(),
Err(_e) => bad_guc_literal(name, "should be a valid UTF-8 string"),
}
}
let base_url = parse(&OPENAI_BASE_URL, "vectors.openai_base_url");
let api_key = parse(&OPENAI_API_KEY, "vectors.openai_api_key");
OpenAIOptions { base_url, api_key }
}

Expand Down
22 changes: 4 additions & 18 deletions src/gucs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use crate::error::*;
use pgrx::guc::GucSetting;
use std::ffi::CStr;

pub mod embedding;
pub mod executing;
pub mod internal;
Expand All @@ -13,19 +9,9 @@ pub unsafe fn init() {
internal::init();
executing::init();
embedding::init();
}
}

fn guc_string_parse(
target: &'static GucSetting<Option<&'static CStr>>,
name: &'static str,
) -> String {
let value = match target.get() {
Some(s) => s,
None => bad_guc_literal(name, "should not be `NULL`"),
};
match value.to_str() {
Ok(s) => s.to_string(),
Err(_e) => bad_guc_literal(name, "should be a valid UTF-8 string"),
#[cfg(feature = "pg14")]
pgrx::pg_sys::EmitWarningsOnPlaceholders(c"vectors".as_ptr());
#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
pgrx::pg_sys::MarkGUCPrefixReserved(c"vectors".as_ptr());
}
}

0 comments on commit b3d3243

Please sign in to comment.