Coder Social home page Coder Social logo

nagyist / postgresql-swift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from loganwright/postgresql-swift

0.0 1.0 0.0 6.88 MB

Swift PostgreSQL driver

License: MIT License

Makefile 0.69% Ruby 0.04% Swift 68.39% Objective-C 17.50% Shell 3.46% C 9.92%

postgresql-swift's Introduction

Connect to your PostgreSQL database. Run queries. All natively in Swift.

Installation

Install via swift-package-manager by adding a depdendency to your Package.swift.

.Package(url: "https://github.com/stepanhruda/PostgreSQL-Swift.git", majorVersion: 0)

Usage

Connection

let parameters = ConnectionParameters(
  host: "123.123.123.123",
  port: "9000",
  databaseName: "banana_pantry",
  login: "mehungry",
  password: "reallyhungrygotnopatience"
)
let connection = try Database.connect(parameters: parameters)

Environment variables

Your database configuration should not be in your application's source. Connecting to the database becomes as easy as:

let connection = try Database.connect()

Configuration is automatically loaded from default PostgreSQL environment variables.

export PGHOST 123.123.123.123
export PGPORT 9000
export PGDATABASE banana_pantry
export PGUSER mehungry
export PGPASSWORD reallyhungrygotnopatience

Queries and results

let result = try connection.execute("SELECT color, is_tasty, length FROM bananas")
for row in result.rows {
  let color = row["color"] as! String
  let isTasty = row["is_tasty"] as! Bool
  let length = row["length"] as! Int
  let banana = Banana(color: color, isTasty: isTasty, length: length)
}

Development on OS X

  1. Install dependencies
  • Xcode 7+ (Swift 2.x)
  • brew cask install dockertoolbox
  1. make development.setup
  • Starts a PostgreSQL container that tests can be run against. Before running make sure your docker-machine environment variables are available (usually you run eval $(docker-machine env default))
  • development.setup also adds handy opinionated environment variables to your Xcode scheme that connect to the container. If you are using a custom setup rather than what docker-machine gives you out of the box, you might need to tweak them. Also, please don't commit any changes to the .xcscheme file.
  1. make test to run tests or run them through Xcode

postgresql-swift's People

Contributors

akatz avatar loganwright avatar stepanhruda avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.