A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.

Overview

Perfect - PostgreSQL Connector

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 4.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

This project provides a Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.

This package builds with Swift Package Manager and is part of the Perfect project. It was written to be stand-alone and so does not require PerfectLib or any other components.

Ensure you have installed and activated the latest Swift 4.0 tool chain.

macOS Build Notes

This package requires the Home Brew build of PostgreSQL.

To install Home Brew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To install postgres:

brew install postgres

Linux Build Notes

Ensure that you have installed libpq-dev.

sudo apt-get install libpq-dev

Building

Add this project as a dependency in your Package.swift file.

.Package(url: "https://github.com/PerfectlySoft/Perfect-PostgreSQL.git", majorVersion: 3)

Documentation

For more information, please visit perfect.org.

Comments
  • Added functions for sending COPY data

    Added functions for sending COPY data

    Added copy functions for sending COPY data. These are described here:

    https://www.postgresql.org/docs/9.4/static/libpq-copy.html

    These functions are fantastic for seeding or importing mass data and could not be exposed via an extension due to the fact that conn is internal only.

    opened by dmonagle 1
  • error: could not build Objective-C module 'libpq'

    error: could not build Objective-C module 'libpq'

    I'm having trouble installing Perfect-PostgreSQL. Everything builds fine before adding Perfect-PostgreSQL.

    Most of the output below are warnings, but the last two are errors.

    Command Line Tools: Xcode 8.0 (8S128d) Toolchain: Swift Development Snapshot 06-20-16 (DEVELOPMENT-SNAPSHOT-2016-06-20-a) I am using swiftenv $ swiftenv global is DEVELOPMENT-SNAPSHOT-2016-06-20-a $ swiftenv version is DEVELOPMENT-SNAPSHOT-2016-06-20-a (set by /Users/mrferrucci/.swiftenv/version)

     → [swiftyAPI]  swift build
    Cloning https://github.com/PerfectlySoft/Perfect.git
    HEAD is now at b457d53 Fixed bad header name check in addHeader
    Resolved version: 0.42.0
    Cloning https://github.com/PerfectlySoft/Perfect-Net.git
    HEAD is now at 89c5036 Linux compilation
    Resolved version: 0.13.0
    Cloning https://github.com/PerfectlySoft/Perfect-OpenSSL.git
    HEAD is now at 7811035 OpenSSL package
    Resolved version: 0.3.0
    Cloning https://github.com/PerfectlySoft/Perfect-Thread.git
    HEAD is now at 471014f Updated for 6-20 snapshot
    Resolved version: 0.10.0
    Compile Swift Module 'PerfectThread' (2 sources)
    Compile Swift Module 'PerfectNet' (5 sources)
    Compile Swift Module 'PerfectLib' (26 sources)
    Compile Swift Module 'swiftyAPI' (1 sources)
    Linking .build/debug/swiftyAPI
     → [swiftyAPI]  swift package generate-xcodeproj
    generated: ./swiftyAPI.xcodeproj
     → [swiftyAPI]
     → [swiftyAPI] 
    

    This is where I added .Package(url: "https://github.com/PerfectlySoft/Perfect-PostgreSQL.git", majorVersion: 0, minor: 1) to my Package.swift file.

     → [swiftyAPI]  swift build
    Cloning https://github.com/PerfectlySoft/Perfect-PostgreSQL.git
    HEAD is now at 106e339 Updates for SPM support
    Resolved version: 0.1.0
    Cloning https://github.com/PerfectlySoft/Perfect-libpq.git
    HEAD is now at 1e7555a Initial commit
    Resolved version: 0.1.0
    Compile Swift Module 'PostgreSQL' (1 sources)
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:136:24: warning: extraneous duplicate parameter name; 'index' already has an argument label
            public func fieldName(index index: Int) -> String? {
                                  ^~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:151:24: warning: extraneous duplicate parameter name; 'index' already has an argument label
            public func fieldType(index index: Int) -> Oid? {
                                  ^~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:162:26: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func fieldIsNull(tupleIndex tupleIndex: Int, fieldIndex: Int) -> Bool {
                                    ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:167:29: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func getFieldString(tupleIndex tupleIndex: Int, fieldIndex: Int) -> String? {
                                       ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:182:26: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func getFieldInt(tupleIndex tupleIndex: Int, fieldIndex: Int) -> Int? {
                                    ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:190:27: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func getFieldBool(tupleIndex tupleIndex: Int, fieldIndex: Int) -> Bool? {
                                     ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:198:27: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func getFieldInt8(tupleIndex tupleIndex: Int, fieldIndex: Int) -> Int8? {
                                     ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:206:28: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func getFieldInt16(tupleIndex tupleIndex: Int, fieldIndex: Int) -> Int16? {
                                      ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:214:28: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func getFieldInt32(tupleIndex tupleIndex: Int, fieldIndex: Int) -> Int32? {
                                      ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:222:28: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func getFieldInt64(tupleIndex tupleIndex: Int, fieldIndex: Int) -> Int64? {
                                      ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:230:29: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func getFieldDouble(tupleIndex tupleIndex: Int, fieldIndex: Int) -> Double? {
                                       ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:238:28: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func getFieldFloat(tupleIndex tupleIndex: Int, fieldIndex: Int) -> Float? {
                                      ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:246:27: warning: extraneous duplicate parameter name; 'tupleIndex' already has an argument label
            public func getFieldBlob(tupleIndex tupleIndex: Int, fieldIndex: Int) -> [Int8]? {
                                     ^~~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:319:19: warning: extraneous duplicate parameter name; 'statement' already has an argument label
            public func exec(statement statement: String) -> PGResult {
                             ^~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:325:19: warning: extraneous duplicate parameter name; 'statement' already has an argument label
            public func exec(statement statement: String, params: [String]) -> PGResult {
                             ^~~~~~~~~~
    
    /Users/joe/Developer/swiftyAPI/Packages/libpq-0.1.0/module.modulemap:2:12: error: header '/usr/local/include/libpq-fe.h' not found
        header "/usr/local/include/libpq-fe.h"
               ^
    /Users/joe/Developer/swiftyAPI/Packages/PostgreSQL-0.1.0/Sources/PostgreSQL/PostgreSQL.swift:21:8: error: could not build Objective-C module 'libpq'
    import libpq
           ^
    <unknown>:0: error: build had 1 command failures
    error: exit(1): /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a.xctoolchain/usr/bin/swift-build-tool -f /Users/joe/Developer/swiftyAPI/.build/debug.yaml
     → [swiftyAPI]
    
    opened by JoeFerrucci 1
  • Modified PostgresExeDelegate.hasNext() to throw an exception rather than returning empty-iterator

    Modified PostgresExeDelegate.hasNext() to throw an exception rather than returning empty-iterator

    PostgresExeDelegate.hasNext() returned false if a connection error occured. I guess it should throw an exception to identify a connection error and empty-result.

    The logic returning false on connection errors is below:

    • PQexec/PQexecParams returns NULL on connection errors.
    • PGConnection.exec returns PGResult which .res == nil.
    • PGResult.status() returns .unknown.
    • PostgresExeDelegate.hasNext() returns false.

    So I modified PostgresExeDelegate.hasNext() to check PGResult.res is nil or not.

    opened by natsuki14 0
  • ISS 574 Notice Receiver

    ISS 574 Notice Receiver

    1. Adding more ignorable items
    2. Removing old syntax of minor version in Package.swift
    3. Adding setReceiver(handler: (PGResult) -> Void) and setProcessor(handler: (String)->Void)
    4. Adding test scripts.
    opened by RockfordWei 0
  • Allow NULL return for modeled variables stored in Postgres

    Allow NULL return for modeled variables stored in Postgres

    This PR is in preparation for another PR for StORM.

    I did see a PR for this same functionality back in April, but it looks like it will give some conflicts.

    The idea of this PR is not just to fix PerfectPostgresSQL return of an actual null value in the database to correctly reflect in your model, but is also intended for the following updates to StORM & PostgresStORM:

    This will support the following updates to StORM:

    • Embedded mirroring through all the necessary superclasses to pull out the labels/values like StORM implementing through the one level deep mirroring. This includes easier identification of primary keys and subclassing support.
    • Support for optional declared variables.

    This will support the following updates to PostgresStORM:

    • Adds support for subclassing PostgresStORM models.
    • Adds support for optional variables for updating, inserting, creating & setup of database tables.
    • Adds support to automatically create an incrementing sequence for integer primary keys.
    • Adds support for automatic created/modified fields to update on create/save functions.
    • Adds support for automatic created by/modifiedby user_id strings by using a new save function specifying the auditUserId.

    I will plan on giving examples in the README so if PerfectlySoft decides to use these updates, they can take the examples & update the main website that contains most of the documentation.

    Let me know if this would affect the future roadmaps for these frameworks - I would not mind making it comply for any future updates.

    opened by ryancoyne 0
  • Add API to consume notifications

    Add API to consume notifications

    Based on https://www.postgresql.org/docs/9.4/static/libpq-notify.html

    Doesn't do anything fancy like callbacks or queues. Just a function to read the next notification if any is available.

    opened by hasenj 0
  • Patching Null Parameter binding.

    Patching Null Parameter binding.

    According to @cocoapriest’s null parameter question, now sql statement conn.exec(statement: "INSERT INTO users (nickname, email) VALUES ($1, $2)", params: ["name", nil]) is allowed and correct in production. Tested both on Linux/Mac with Swift 3.1

    opened by RockfordWei 0
  • create PGResultSet and PGRow classes in the PostgreSQL library

    create PGResultSet and PGRow classes in the PostgreSQL library

    These two classes provide row based access to the results of a query for the PostgreSQL connector. As a starting point, they bring conformance to both Sequence and IteratorProtocol, allowing both for - in loops and subscript behavior. Together they make the Postgres connector more accessible for developers.

    This is a starting point/suggestion and needs further work. For example, the PGRow needs more of the fieldType integers to be handled, but I couldn't find a reference to those type integers.

    With these two classes, it is easier to build data objects that reference the Postgres data records.

    opened by taplin 0
  • Wrong dependency information on GitPage

    Wrong dependency information on GitPage

    Add this project as a dependency in your Package.swift file. .Package(url: "https://github.com/PerfectlySoft/Perfect-PostgreSQL.git", majorVersion: 3)

    • Package is incorrect as Swift now uses lowerscore Package.
    • majorVersion is incorrect as its now "from"
    • 3 is incorrect as its now "3.0.0"

    So the correct syntax needs to be:

    .package(url: "https://github.com/PerfectlySoft/Perfect-PostgreSQL.git", from: "3.0.0"),

    opened by Indribell 0
  • Made PGConnection thread-safe.

    Made PGConnection thread-safe.

    I found PGConnection is not thread-safe. This causes critical errors on multi-threaded applications (e.g. applications based on Perfect-HTTPServer). To make it thread-safe, I introduced a lock to protect libpq connection (PGConnection.conn).

    opened by natsuki14 0
  • update PGResult and create PGRow class in the PostgreSQL library, plus quickstart

    update PGResult and create PGRow class in the PostgreSQL library, plus quickstart

    Updated PGResult to conform to Sequence and IteratorProtocol, created PGRow struct to handle the row based access. Added Tests to cover new functionality.

    Also created quickstart examples to illustrate usage.

    opened by taplin 0
Owner
PerfectlySoft Inc.
Server-side Swift
PerfectlySoft Inc.
MySQL client library for Swift. This is inspired by Node.js' mysql.

mysql-swift MySQL client library for Swift. This is inspired by Node.js' mysql. Based on libmysqlclient Raw SQL query Simple query formatting and esca

Yusuke Ito 155 Nov 19, 2022
SQLiteDB is a simple and lightweight SQLite wrapper for Swift

Basic SQLite wrapper for Swift 4.x and lightweight ORM for accessing underlying tables in an SQLite database

Fahim Farook 559 Jan 4, 2023
SQLite.swift provides compile-time confidence in SQL statement syntax and intent.

SQLite.swift A type-safe, Swift-language layer over SQLite3. SQLite.swift provides compile-time confidence in SQL statement syntax and intent. Feature

Stephen Celis 8.7k Jan 8, 2023
A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers.

Perfect - PostgreSQL Connector This project provides a Swift wrapper around the libpq client library, enabling access to PostgreSQL servers. This pack

PerfectlySoft Inc. 51 Nov 19, 2022
A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers.

This package is deprecated in favour of the official Mongo Swift Driver. We advise users to switch to that pack

PerfectlySoft Inc. 54 Jul 9, 2022
A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers.

Perfect - MySQL Connector This project provides a Swift wrapper around the MySQL client library, enabling access to MySQL database servers. This packa

PerfectlySoft Inc. 118 Jan 1, 2023
A stand-alone Swift wrapper around the FileMaker XML Web publishing interface, enabling access to FileMaker servers.

Perfect - FileMaker Server Connector This project provides access to FileMaker Server databases using the XML Web publishing interface. This package b

PerfectlySoft Inc. 33 Jul 13, 2022
Perfect - a Swift wrapper around the MySQL client library, enabling access to MySQL database servers.

Perfect - MySQL Connector This project provides a Swift wrapper around the MySQL client library, enabling access to MySQL database servers. This packa

PerfectlySoft Inc. 119 Dec 16, 2022
A stand-alone Swift wrapper around the SQLite 3 client library.

Perfect - SQLite Connector This project provides a Swift wrapper around the SQLite 3 library. This package builds with Swift Package Manager and is pa

PerfectlySoft Inc. 47 Nov 19, 2022
A PostgreSQL client library for Swift. Does not require libpq.

PostgresClientKit PostgresClientKit provides a friendly Swift API for operating against a PostgreSQL database. Features Doesn't require libpq. Postgre

codewins.com 107 Dec 1, 2022
A wrapper around UICollectionViewController enabling a declarative API around it's delegate methods using protocols.

Thunder Collection Thunder Collection is a useful framework which enables quick and easy creation of collection views in iOS using a declarative appro

3 SIDED CUBE 4 Nov 6, 2022
A swift client for interacting with NATS servers

SwiftyNats A maintained swift client for interacting with a nats server based on NIO2. Tested with Swift 5.4 on and Swift Version Compatibility: Platf

aus der Technik - Simon & Simon GbR 25 Dec 15, 2022
`Republished` is a property wrapper enabling nested ObservableObjects in SwiftUI.

Republished The @Republished proprty wrapper allows an ObservableObject nested within another ObservableObject to naturally notify SwiftUI of changes.

Adam Zethraeus 13 Dec 5, 2022
Listens to changes in a PostgreSQL Database and via websockets.

realtime-swift Listens to changes in a PostgreSQL Database and via websockets. A Swift client for Supabase Realtime server. Usage Creating a Socket co

Supabase 35 Dec 1, 2022
PostgreSQL database adapter (ORM included)

PostgreSQL PostgreSQL adapter for Swift 3.0. Conforms to SQL, which provides a common interface and ORM. Documentation can be found there. Installatio

Zewo Graveyard 91 Sep 9, 2022
Campus Atlas -- a Mapping & GIS solution which provides easy access to navigating the campus around you.

Campus Atlas Welcome to Campus Atlas -- a Mapping & GIS solution which provides easy access to navigating the campus around you. Technical Implementat

Larry Tseng 5 Nov 12, 2021
A lightweight library for writing HTTP web servers with Swift

Taylor Disclaimer: Not actively working on it anymore. You can check out some alternatives Swift 2.0 required. Working with Xcode 7.1. Disclaimer: It

Jorge Izquierdo 925 Nov 17, 2022
A lightweight library for writing HTTP web servers with Swift

Taylor Disclaimer: Not actively working on it anymore. You can check out some alternatives Swift 2.0 required. Working with Xcode 7.1. Disclaimer: It

Jorge Izquierdo 925 Nov 17, 2022
μ-library enabling if/else and switch statements to be used as expressions.

swift-expression Many languages such as Scala, Rust and Kotlin support using if/else and switch statements as expressions – meaning that they can by t

Nikita Mounier 1 Nov 8, 2021
GraphQLite is a toolkit to work with GraphQL servers easily. It also provides several other features to make life easier during iOS application development.

What is this? GraphQLite is a toolkit to work with GraphQL servers easily. It also provides several other features to make life easier during iOS appl

Related Code 2.8k Jan 9, 2023