Skip to content

bug: Can't use postgresql-service #5959

@Iam-WenYi

Description

@Iam-WenYi

Describe the bug

The example code gived in postgresql's service markfodown document can't run.

Steps to Reproduce

  1. Make a copy of ofs directory, rename to postgresql-opendal-try/
  2. Chanage Cargo.toml to this:
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

[package]
categories = ["postgresql-service-example"]
description = "OpenDAL PostgreSQL Service Example"
keywords = ["storage", "data", "postgresql"]
name = "postgresql-service-example"
version = "0.0.1"

authors = ["Wen Yi <wen-yi@qq.com>"]
edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.80"

[dependencies]
anyhow = { version = "1" }
clap = { version = "4.5.21", features = ["derive", "env"] }
log = { version = "0.4.22" }
logforth = { version = "0.23.1", default-features = false }
opendal = { version = "0.53.0", path = "../../core" }
tokio = { version = "1.37.0", features = [
  "fs",
  "macros",
  "rt-multi-thread",
  "io-std",
  "signal",
] }
url = { version = "2.5.4" }

[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))'.dependencies]
fuse3 = { version = "0.8.1", "features" = ["tokio-runtime", "unprivileged"] }
fuse3_opendal = { version = "0.0.14", path = "../../integrations/fuse3" }
libc = "0.2.154"
nix = { version = "0.29.0", features = ["user"] }

[target.'cfg(target_os = "windows")'.dependencies]
cloud-filter = { version = "0.0.5" }
cloud_filter_opendal = { version = "0.0.7", path = "../../integrations/cloud_filter" }

[features]
default = ["services-fs", "services-s3"]
services-fs = ["opendal/services-fs"]
services-s3 = ["opendal/services-s3"]

[dev-dependencies]
opendal = { version = "0.53.0", path = "../../core", features = ["tests"] }
tempfile = "3.16.0"
test-context = "0.4.1"
walkdir = "2.5.0"
  1. Change main.rs to this:
use anyhow::Result;
use opendal::services::Postgresql;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
    let mut builder = Postgresql::default()
        .root("/")
        .connection_string("postgresql://you_username:your_password@127.0.0.1:5432/your_database")
        .table("your_table")
        // key field type in the table should be compatible with Rust's &str like text
        .key_field("key")
        // value field type in the table should be compatible with Rust's Vec<u8> like bytea
        .value_field("value");

    let op = Operator::new(builder)?.finish();
    Ok(())
}
  1. Cargo build

Image

Expected Behavior

I want to use the OpenDAL to connect to the postgresql, but I can't

Additional Context

No response

Are you willing to submit a PR to fix this bug?

  • Yes, I would like to submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions