All Projects → codewinsdotcom → Postgresclientkit

codewinsdotcom / Postgresclientkit

Licence: apache-2.0
A PostgreSQL client library for Swift. Does not require libpq.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Postgresclientkit

Awesome Postgres
A curated list of awesome PostgreSQL software, libraries, tools and resources, inspired by awesome-mysql
Stars: ✭ 7,468 (+15140.82%)
Mutual labels:  database, postgresql, postgres
Pgmetrics
Collect and display information and stats from a running PostgreSQL server
Stars: ✭ 612 (+1148.98%)
Mutual labels:  database, postgresql, postgres
Sqlboiler
Generate a Go ORM tailored to your database schema.
Stars: ✭ 4,497 (+9077.55%)
Mutual labels:  database, postgresql, postgres
Perfect Postgresql
A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.
Stars: ✭ 48 (-2.04%)
Mutual labels:  database, postgresql, server-side-swift
Docker Postgres
A docker container running PostgreSQL
Stars: ✭ 22 (-55.1%)
Mutual labels:  database, postgresql, postgres
Ansible Role Postgresql
Ansible Role - PostgreSQL
Stars: ✭ 310 (+532.65%)
Mutual labels:  database, postgresql, postgres
Goqu
SQL builder and query library for golang
Stars: ✭ 984 (+1908.16%)
Mutual labels:  database, postgresql, postgres
Rpostgres
A DBI-compliant interface to PostgreSQL
Stars: ✭ 245 (+400%)
Mutual labels:  database, postgresql, postgres
Efcore.pg
Entity Framework Core provider for PostgreSQL
Stars: ✭ 838 (+1610.2%)
Mutual labels:  database, postgresql, postgres
Metabase
The simplest, fastest way to get business intelligence and analytics to everyone in your company 😋
Stars: ✭ 26,803 (+54600%)
Mutual labels:  database, postgresql, postgres
Dbq
Zero boilerplate database operations for Go
Stars: ✭ 273 (+457.14%)
Mutual labels:  database, postgresql, postgres
Go Kallax
Kallax is a PostgreSQL typesafe ORM for the Go language.
Stars: ✭ 853 (+1640.82%)
Mutual labels:  database, postgresql, postgres
Pg chameleon
MySQL to PostgreSQL replica system
Stars: ✭ 274 (+459.18%)
Mutual labels:  database, postgresql, postgres
Jet
Type safe SQL builder with code generation and automatic query result data mapping
Stars: ✭ 373 (+661.22%)
Mutual labels:  database, postgresql, postgres
Postgui
A React web application to query and share any PostgreSQL database.
Stars: ✭ 260 (+430.61%)
Mutual labels:  database, postgresql, postgres
Citus
Distributed PostgreSQL as an extension
Stars: ✭ 5,580 (+11287.76%)
Mutual labels:  database, postgresql, postgres
Massive Js
A data mapper for Node.js and PostgreSQL.
Stars: ✭ 2,521 (+5044.9%)
Mutual labels:  database, postgresql, postgres
Prest
PostgreSQL ➕ REST, low-code, simplify and accelerate development, ⚡ instant, realtime, high-performance on any Postgres application, existing or new
Stars: ✭ 3,023 (+6069.39%)
Mutual labels:  database, postgresql, postgres
Blog
Everything about database,business.(Most for PostgreSQL).
Stars: ✭ 6,330 (+12818.37%)
Mutual labels:  database, postgresql, postgres
Node Pg Migrate
Node.js database migration management for Postgresql
Stars: ✭ 838 (+1610.2%)
Mutual labels:  database, postgresql, postgres

PostgresClientKit

PostgresClientKit provides a friendly Swift API for operating against a PostgreSQL database.

Features

  • Doesn't require libpq. PostgresClientKit implements the Postgres network protocol in Swift, so it does not require libpq.

  • Developer-friendly API using modern Swift. For example, errors are represented by instances of enum PostgresError: Error and are raised by a throw or by returning a Result<Success, Error>.

  • Safe conversion between Postgres and Swift types. Type conversion is explicit and robust. Conversion errors are signaled, not masked. PostgresClientKit provides additional Swift types for dates and times to address the impedance mismatch between Postgres types and Foundation Date.

  • Memory efficient. The rows in a result are exposed through an iterator, not an array. Rows are lazily retrieved from the Postgres server.

  • SSL/TLS support. Encrypts the connection between PostgresClientKit and the Postgres server.

  • Well-engineered. Complete API documentation, an extensive test suite, actively supported.

Sounds good? Let's look at an example.

Example

This is a basic, but complete, example of how to connect to Postgres, perform a SQL SELECT command, and process the resulting rows. It uses the weather table in the Postgres tutorial.

import PostgresClientKit

do {
    var configuration = PostgresClientKit.ConnectionConfiguration()
    configuration.host = "127.0.0.1"
    configuration.database = "example"
    configuration.user = "bob"
    configuration.credential = .scramSHA256(password: "welcome1")

    let connection = try PostgresClientKit.Connection(configuration: configuration)
    defer { connection.close() }

    let text = "SELECT city, temp_lo, temp_hi, prcp, date FROM weather WHERE city = $1;"
    let statement = try connection.prepareStatement(text: text)
    defer { statement.close() }

    let cursor = try statement.execute(parameterValues: [ "San Francisco" ])
    defer { cursor.close() }

    for row in cursor {
        let columns = try row.get().columns
        let city = try columns[0].string()
        let tempLo = try columns[1].int()
        let tempHi = try columns[2].int()
        let prcp = try columns[3].optionalDouble()
        let date = try columns[4].date()
    
        print("""
            \(city) on \(date): low: \(tempLo), high: \(tempHi), \
            precipitation: \(String(describing: prcp))
            """)
    }
} catch {
    print(error) // better error handling goes here
}

Output:

San Francisco on 1994-11-27: low: 46, high: 50, precipitation: Optional(0.25)
San Francisco on 1994-11-29: low: 43, high: 57, precipitation: Optional(0.0)

Prerequisites

  • Swift 5 or later (PostgresClientKit uses Swift 5 language features)
  • libssl-dev (only required on Linux)

PostgresClientKit is compatible with Linux, macOS, and iOS. It has been tested on:

  • Ubuntu 18.04 LTS, 20.04 LTS
  • macOS 10.14, 10.15, 11.1
  • iOS 12, 13, 14
  • Postgres 10, 11, 12, 13

Building

cd <path-to-clone>
swift package clean
swift build

Testing

Set up a Postgres database for testing. This is a one-time process.

Then:

cd <path-to-clone>
swift package clean
swift build
swift test

Using

Swift Package Manager

In your Package.swift file:

  • Add PostgresClientKit to the dependencies. For example:
dependencies: [
    .package(url: "https://github.com/codewinsdotcom/PostgresClientKit", from: "1.0.0"),
],
  • Reference the PostgresClientKit product in the targets. For example:
targets: [
    .target(
        name: "MyProject",
        dependencies: ["PostgresClientKit"]),
]

Import to your source code file:

import PostgresClientKit

CocoaPods

Add PostgresClientKit to your Podfile. For example:

target 'MyApp' do
  pod 'PostgresClientKit', '~> 1.0'
end

Then run pod install.

Import to your source code file:

import PostgresClientKit

Documentation

Additional examples

Contributing

Thank you for your interest in contributing to PostgresClientKit.

This project has a code of conduct. See CODE_OF_CONDUCT.md for details.

Please use issues to:

  • ask questions
  • report problems (bugs)
  • request enhancements

Pull requests against the develop branch are welcomed. For a non-trivial contribution (for example, more than correcting spelling, typos, or whitespace) please first discuss the proposed change by opening an issue.

License

PostgresClientKit is licensed under the Apache 2.0 license. See LICENSE for details.

Versioning

PostgresClientKit uses Semantic Versioning 2.0.0. For the versions available, see the tags on this repository.

Built with

Authors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].