Movatterモバイル変換


[0]ホーム

URL:


Docs.rs

Cratepostgres [][src]

A pure-Rust frontend for the popular PostgreSQL database.

externcratepostgres;usepostgres::{Connection,TlsMode};structPerson {id:i32,name:String,data:Option<Vec<u8>>}fnmain() {letconn=Connection::connect("postgresql://postgres@localhost:5433",TlsMode::None)            .unwrap();conn.execute("CREATE TABLE person (                    id              SERIAL PRIMARY KEY,                    name            VARCHAR NOT NULL,                    data            BYTEA                  )",&[]).unwrap();letme=Person {id:0,name:"Steven".to_owned(),data:None    };conn.execute("INSERT INTO person (name, data) VALUES ($1, $2)",&[&me.name,&me.data]).unwrap();forrowin&conn.query("SELECT id, name, data FROM person",&[]).unwrap() {letperson=Person {id:row.get(0),name:row.get(1),data:row.get(2)        };println!("Found person {}",person.name);    }}

SSL/TLS

This crate supports TLS secured connections. TheTlsMode enum is passed to connection methodsand indicates if the connection will not, may, or must be secured by TLS. The TLS implementationis pluggable through theTlsHandshake trait. Implementations for OpenSSL, Secure Transport,SChannel, and thenative-tls crate are provided behind thewith-openssl,with-security-framework,with-schannel, andwith-native-tls feature flags respectively.

Examples

Connecting usingnative-tls:

externcratepostgres;usepostgres::{Connection,TlsMode};usepostgres::tls::native_tls::NativeTls;fnmain() {letnegotiator=NativeTls::new().unwrap();letconn=Connection::connect("postgres://postgres@localhost:5433",TlsMode::Require(&negotiator))        .unwrap();}

Modules

error

Errors.

notification

Asynchronous notifications.

params

Connection parameters

rows

Query result rows.

stmt

Prepared statements

tls

Types and traits for TLS support.

transaction

Transactions

types

Types.

Macros

accepts

Generates a simple implementation ofToSql::accepts which accepts thetypes passed to it.

to_sql_checked

Generates an implementation ofToSql::to_sql_checked.

Structs

CancelData

Contains information necessary to cancel queries for a session.

Connection

A connection to a Postgres database.

Error

An error communicating with the Postgres server.

LoggingNoticeHandler

A notice handler which logs at theinfo level.

Enums

TlsMode

Specifies the TLS support requested for a new connection.

Traits

GenericConnection

A trait allowing abstraction over connections and transactions

HandleNotice

A trait implemented by types that can handle Postgres notice messages.

Functions

cancel_query

Attempts to cancel an in-progress query.

Type Definitions

Result

A type alias of the result returned by many methods.

Help

Keyboard Shortcuts

?
Show this help dialog
S
Focus the search field
Move up in search results
Move down in search results
Go to active search result
+
Collapse/expand all sections

Search Tricks

Prefix searches with a type followed by a colon (e.g.fn:) to restrict the search to a given type.

Accepted types are:fn,mod,struct,enum,trait,type,macro, andconst.

Search functions by type signature (e.g.vec -> usize or* -> vec)


[8]
ページ先頭

©2009-2025 Movatter.jp