Movatterモバイル変換


[0]ホーム

URL:


Docs.rs

[][src]Cratepostgres

A synchronous client for the PostgreSQL database.

Example

usepostgres::{Client,NoTls};letmutclient=Client::connect("host=localhost user=postgres",NoTls)?;client.batch_execute("    CREATE TABLE person (        id      SERIAL PRIMARY KEY,        name    TEXT NOT NULL,        data    BYTEA    )")?;letname="Ferris";letdata=None::<&[u8]>;client.execute("INSERT INTO person (name, data) VALUES ($1, $2)",&[&name,&data],)?;forrowinclient.query("SELECT id, name, data FROM person",&[])? {letid:i32=row.get(0);letname:&str=row.get(1);letdata:Option<&[u8]>=row.get(2);println!("found person: {} {} {:?}",id,name,data);}

Implementation

This crate is a lightweight wrapper over tokio-postgres. Thepostgres::Client is simply a wrapper around atokio_postgres::Client along side a tokioRuntime. The client simply blocks on the futures provided by the asyncclient.

SSL/TLS support

TLS support is implemented via external libraries.Client::connect andConfig::connect take a TLS implementationas an argument. TheNoTls type in this crate can be used when TLS is not required. Otherwise, thepostgres-openssl andpostgres-native-tls crates provide implementations backed by theopenssl andnative-tlscrates, respectively.

Re-exports

pub usefallible_iterator;
pub use crate::config::Config;
pub use crate::error::Error;
pub use crate::row::Row;
pub use crate::row::SimpleQueryRow;
pub use crate::tls::NoTls;

Modules

binary_copy

Utilities for working with the PostgreSQL binary copy format.

config

Connection configuration.

error

Errors.

row

Rows.

tls

TLS support.

types

Types.

Structs

CancelToken

The capability to request cancellation of in-progress queries on aconnection.

Client

A synchronous PostgreSQL client.

Column

Information about a column of a query.

CopyInWriter

The writer returned by thecopy_in method.

CopyOutReader

The reader returned by thecopy_out method.

Portal

A portal.

RowIter

The iterator returned byquery_raw.

Socket

The standard stream type used by the crate.

Statement

A prepared statement.

Transaction

A representation of a PostgreSQL database transaction.

TransactionBuilder

A builder for database transactions.

Enums

IsolationLevel

The isolation level of a database transaction.

SimpleQueryMessage

Message returned by theSimpleQuery stream.

Traits

GenericClient

A trait allowing abstraction over connections and transactions.

ToStatement

A trait abstracting over prepared and unprepared statements.


[8]ページ先頭

©2009-2025 Movatter.jp