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.
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
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
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
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
A Cocoa / Objective-C wrapper around SQLite

FMDB v2.7 This is an Objective-C wrapper around SQLite. The FMDB Mailing List: https://groups.google.com/group/fmdb Read the SQLite FAQ: https://www.s

August 13.7k Dec 28, 2022
Simplified access to Apple's CloudKit

EVCloudKitDao Discuss EVCloudKitDao : What is this With Apple CloudKit, you can focus on your client-side app development and let iCloud eliminate the

Edwin Vermeer 632 Dec 29, 2022
An alternative to Core Data for people who like having direct SQL access.

FCModel 2 An alternative to Core Data for people who like having direct SQL access. By Marco Arment. See the LICENSE file for license info (it's the M

null 1.7k Dec 28, 2022
Easy direct access to your database 🎯

OHMySQL ★★ Every star is appreciated! ★★ The library supports Objective-C and Swift, iOS and macOS. You can connect to your remote MySQL database usin

Oleg 210 Dec 28, 2022
iForage helps foragers to track and manage foraging spots around them using CloudKit

iForage CloudKit Preface To expand on what I've created here: https://github.com/LynchConnor/iForage, I initially developed the app using Firebase. Th

Connor Lynch 3 Jul 14, 2022
CoreData/Realm sweet wrapper written in Swift

What is SugarRecord? SugarRecord is a persistence wrapper designed to make working with persistence solutions like CoreData in a much easier way. Than

Modo 2.1k Dec 9, 2022
A Swift wrapper for system shell over posix_spawn with search path and env support.

AuxiliaryExecute A Swift wrapper for system shell over posix_spawn with search path and env support. Usage import AuxiliaryExecute AuxiliaryExecute.l

Lakr Aream 11 Sep 13, 2022
A Swift wrapper for SQLite databases

Squeal, a Swift interface to SQLite Squeal provides access to SQLite databases in Swift. Its goal is to provide a simple and straight-forward base API

Christian Niles 297 Aug 6, 2022
An Objective-C wrapper for RocksDB - A Persistent Key-Value Store for Flash and RAM Storage.

ObjectiveRocks ObjectiveRocks is an Objective-C wrapper of Facebook's RocksDB - A Persistent Key-Value Store for Flash and RAM Storage. Current RocksD

Iskandar Abudiab 56 Nov 5, 2022
A lightweight wrapper over UserDefaults/NSUserDefaults with an additional layer of AES-256 encryption

SecureDefaults for iOS, macOS Requirements • Usage • Installation • Contributing • Acknowledgments • Contributing • Author • License SecureDefaults is

Victor Peschenkov 216 Dec 22, 2022
A property wrapper for displaying up-to-date database content in SwiftUI views

@Query Latest release: November 25, 2021 • version 0.1.0 • CHANGELOG Requirements: iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+ • Swift 5.5+ /

Gwendal Roué 102 Dec 29, 2022
⚙️ A tiny property wrapper for UserDefaults. Only 60 lines of code.

⚙️ A tiny property wrapper for UserDefaults. Only 60 lines of code. import Persistent extension UserDefaults { // Optional property @Per

Mezhevikin Alexey 6 Sep 28, 2022