Compare commits
2 Commits
01f4e52c64
...
ab113acde5
| Author | SHA1 | Date | |
|---|---|---|---|
| ab113acde5 | |||
| 7391f0f2ce |
+1
-1
@@ -1,6 +1,6 @@
|
||||
name = "GeneralUtils"
|
||||
uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
authors = ["tonaerospace <tonaerospace.etc@gmail.com>"]
|
||||
|
||||
[deps]
|
||||
|
||||
@@ -8,6 +8,36 @@ using ..util
|
||||
#[PENDING] update code to use JSON
|
||||
# ---------------------------------------------- 100 --------------------------------------------- #
|
||||
|
||||
""" Execute SQL against a PostgreSQL database using LibPQ connection string.
|
||||
|
||||
# Arguments
|
||||
- `pg_conn_str::AbstractString`: PostgreSQL connection string in format "host=... port=... dbname=... user=... password=..."
|
||||
- `sql::AbstractString`: SQL query to execute
|
||||
|
||||
# Returns
|
||||
- `LibPQ.Result` on success, `nothing` on failure
|
||||
|
||||
# Example
|
||||
```julia
|
||||
pg_conn_str = "host=localhost port=5432 dbname=mydb user=myuser password=mypass"
|
||||
sql = "SELECT * FROM wine;"
|
||||
result = execute_postgres_sql(pg_conn_str, sql)
|
||||
```
|
||||
"""
|
||||
function execute_postgres_sql(pg_conn_str::T, sql::T) where {T<:AbstractString}
|
||||
db_connection = LibPQ.Connection(pg_conn_str)
|
||||
result = nothing
|
||||
try
|
||||
result = LibPQ.execute(db_connection, sql)
|
||||
catch e
|
||||
@error e
|
||||
LibPQ.close(db_connection)
|
||||
end
|
||||
|
||||
LibPQ.close(db_connection)
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
"""
|
||||
dictToPostgresKeyValueString - Convert dictionary to PostgreSQL key-value string format
|
||||
|
||||
Reference in New Issue
Block a user