Package
PostgresNIO
Overview
PostgresNIO allows you to connect to, authorize with, query, and retrieve results from a PostgreSQL server. PostgreSQL is an open source relational database.
Use a PostgresConnection to create a connection to the PostgreSQL server. You can then use it to run queries and prepared statements against the server. PostgresConnection also supports PostgreSQL’s Listen & Notify API.
Developers, who don’t want to manage connections themselves, can use the PostgresClient, which offers the same functionality as PostgresConnection. PostgresClient pools connections for rapid connection reuse and hides the complexities of connection management from the user, allowing developers to focus on their SQL queries. PostgresClient implements the Service protocol from Service Lifecycle allowing an easy adoption in Swift server applications.
PostgresNIO embraces Swift structured concurrency, offering async/await APIs which handle task cancellation. The query interface makes use of backpressure to ensure that memory can not grow unbounded for queries that return thousands of rows.
PostgresNIO runs efficiently on Linux and Apple platforms. On Apple platforms developers can configure PostgresConnection to use Network.framework as the underlying transport framework.
Topics
Essentials
PostgresClientA Postgres client that is backed by an underlying connection pool. UsePostgresClient.Configurationto change the client’s behavior.PostgresClient.ConfigurationPostgresConnectionA Postgres connection. Use it to run queries against a Postgres server.- Running QueriesInteract with the PostgreSQL database by running Queries.
Advanced
- PostgreSQL data typesTranslate Swift data types to Postgres data types and vica versa. Learn how to write translations for your own custom Swift types.
- Boosting Performance with Prepared StatementsImprove performance by leveraging PostgreSQL’s prepared statements.
- Listen & Notify
PostgresNIOsupports PostgreSQL’s listen and notify API. Learn how to listen for changes and notify other listeners.
Errors
PostgresErrorPostgresDecodingErrorAn error that may happen when aPostgresRoworPostgresCellis decoded to native Swift types.PSQLErrorAn error that is thrown from the PostgresClient. Sendability enforced through copy-on-write semantics.
Deprecations
- Deprecations
PostgresNIOfollows SemVer 2.0.0. Learn which APIs are considered deprecated and how to migrate to their replacements.
Structures
PostgresCopyFromFormatSpecifies the format in which data is transferred to the backend in a COPY operation.PostgresCopyFromWriterHandle to send data for aCOPY ... FROM STDINquery to the backend.PostgresTransactionErrorA wrapper around the errors that can occur during a transaction.