MCPcopy Create free account
hub / github.com/erans/pgsqlite / register_system_functions

Function register_system_functions

src/functions/system_functions.rs:5–468  ·  view source on GitHub ↗

Register PostgreSQL system information functions

(conn: &Connection)

Source from the content-addressed store, hash-verified

3
4/// Register PostgreSQL system information functions
5pub fn register_system_functions(conn: &Connection) -> Result<()> {
6 debug!("Registering system functions");
7
8 // version() - Returns PostgreSQL version string
9 conn.create_scalar_function(
10 "version",
11 0,
12 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
13 |_ctx| {
14 // Return a PostgreSQL-compatible version string
15 // This format is what SQLAlchemy expects to parse
16 Ok(format!("PostgreSQL 16.0 (pgsqlite {}) on x86_64-pc-linux-gnu, compiled by rustc, 64-bit",
17 env!("CARGO_PKG_VERSION")))
18 },
19 )?;
20
21 // current_database() - Returns the current database name
22 conn.create_scalar_function(
23 "current_database",
24 0,
25 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
26 |_ctx| {
27 // In SQLite, we'll return "main" as the database name
28 Ok("main".to_string())
29 },
30 )?;
31
32 // current_schema() - Returns the current schema name
33 conn.create_scalar_function(
34 "current_schema",
35 0,
36 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
37 |_ctx| {
38 // SQLite doesn't have schemas, return "public" for PostgreSQL compatibility
39 Ok("public".to_string())
40 },
41 )?;
42
43 // current_schemas(include_implicit) - Returns array of schemas in search path
44 conn.create_scalar_function(
45 "current_schemas",
46 1,
47 FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
48 |ctx| {
49 let include_implicit: bool = ctx.get(0)?;
50 if include_implicit {
51 // Include system schemas
52 Ok(r#"["pg_catalog","public"]"#.to_string())
53 } else {
54 // Just user schemas
55 Ok(r#"["public"]"#.to_string())
56 }
57 },
58 )?;
59
60 // current_user() - Returns the current user name
61 conn.create_scalar_function(
62 "current_user",

Callers 11

register_all_functionsFunction · 0.85
test_version_functionFunction · 0.85
test_current_databaseFunction · 0.85
test_current_schemaFunction · 0.85
test_current_userFunction · 0.85
test_pg_backend_pidFunction · 0.85
test_pg_is_in_recoveryFunction · 0.85
test_privilege_functionsFunction · 0.85
test_obj_descriptionFunction · 0.85
test_col_descriptionFunction · 0.85

Calls 2

format_size_prettyFunction · 0.85
getMethod · 0.45

Tested by 10

test_version_functionFunction · 0.68
test_current_databaseFunction · 0.68
test_current_schemaFunction · 0.68
test_current_userFunction · 0.68
test_pg_backend_pidFunction · 0.68
test_pg_is_in_recoveryFunction · 0.68
test_privilege_functionsFunction · 0.68
test_obj_descriptionFunction · 0.68
test_col_descriptionFunction · 0.68