PostgreSQL
PostgreSQL services support.
Capabilities
This service can be used to:
- stat
- read
- write
- create_dir
- delete
- copy
- rename
-
list -
presign - blocking
Configuration
root
: Set the working directory ofOpenDAL
connection_string
: Set the connection string of postgres servertable
: Set the table of postgresqlkey_field
: Set the key field of postgresqlvalue_field
: Set the value field of postgresql
Example
Via Builder
use anyhow::Result;
use opendal::services::Postgresql;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
let mut builder = Postgresql::default();
builder.root("/");
builder.connection_string("postgresql://you_username:your_password@127.0.0.1:5432/your_database");
builder.table("your_table");
// key field type in the table should be compatible with Rust's &str like text
builder.key_field("key");
// value field type in the table should be compatible with Rust's Vec<u8> like bytea
builder.value_field("value");
let op = Operator::new(builder)?.finish();
Ok(())
}
Via Config
- Rust
- Node.js
- Python
use anyhow::Result;
use opendal::services::Postgresql;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("connection_string".to_string(), "postgresql://you_username:your_password@127.0.0.1:5432/your_database".to_string());
map.insert("table".to_string(), "your_table".to_string());
map.insert("key_field".to_string(), "your_key_field".to_string());
map.insert("value_field".to_string(), "your_value_field".to_string());
let op: Operator = Operator::via_map(Scheme::Postgresql, map)?;
Ok(())
}
import { Operator } from require('opendal');
async function main() {
const op = new Operator("postgresql", {
connection_string: 'postgresql://you_username:your_password@127.0.0.1:5432/your_database',
table: 'your_table',
key_field: 'your_key_field',
value_field: 'your_value_field',
});
}
import opendal
op = opendal.Operator("postgresql", {
"connection_string": "postgresql://you_username:your_password@127.0.0.1:5432/your_database",
"table": "your_table",
"key_field": "your_key_field",
"value_field": "your_value_field",
})