All Projects → vapor-community → Postgresql

vapor-community / Postgresql

Licence: mit
Robust PostgreSQL interface for Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Postgresql

Sqhell.vim
An SQL wrapper for vim
Stars: ✭ 113 (-11.02%)
Mutual labels:  postgres
Vscode Postgres
PostgreSQL extension for vscode providing explorer, highlighting, diagnostics, and intellisense
Stars: ✭ 117 (-7.87%)
Mutual labels:  postgres
Queues
A queue system for Vapor.
Stars: ✭ 121 (-4.72%)
Mutual labels:  vapor
Sql Kit
*️⃣ Build SQL queries in Swift. Extensible, protocol-based design that supports DQL, DML, and DDL.
Stars: ✭ 115 (-9.45%)
Mutual labels:  vapor
Postgraphile
GraphQL is a new way of communicating with your server. It eliminates the problems of over- and under-fetching, incorporates strong data types, has built-in introspection, documentation and deprecation capabilities, and is implemented in many programming languages. This all leads to gloriously low-latency user experiences, better developer experiences, and much increased productivity. Because of all this, GraphQL is typically used as a replacement for (or companion to) RESTful API services.
Stars: ✭ 10,967 (+8535.43%)
Mutual labels:  postgres
Symfony 4 Docker Env
Docker Environment for Symfony. PHP-FPM, NGINX SSL Proxy, MySQL, LEMP
Stars: ✭ 119 (-6.3%)
Mutual labels:  postgres
Ship Hold
data access framework for Postgresql on nodejs
Stars: ✭ 110 (-13.39%)
Mutual labels:  postgres
Timescaledb
An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.
Stars: ✭ 12,211 (+9514.96%)
Mutual labels:  postgres
Pgcmd
Non-interactive PostgreSQL query tool.
Stars: ✭ 117 (-7.87%)
Mutual labels:  postgres
Postgres Showcase
Postgres features showcase (commented SQL samples) for beginners
Stars: ✭ 121 (-4.72%)
Mutual labels:  postgres
Open Crypto
🔑 Hashing (BCrypt, SHA2, HMAC), encryption (AES), public-key (RSA), and random data generation.
Stars: ✭ 115 (-9.45%)
Mutual labels:  vapor
Postgres Nio
🐘 Non-blocking, event-driven Swift client for PostgreSQL.
Stars: ✭ 117 (-7.87%)
Mutual labels:  vapor
Postgresqlcopyhelper
Simple Wrapper around Npgsql for using PostgreSQL COPY functions.
Stars: ✭ 120 (-5.51%)
Mutual labels:  postgres
Marten
.NET Transactional Document DB and Event Store on PostgreSQL
Stars: ✭ 1,654 (+1202.36%)
Mutual labels:  postgres
Awesome Server Side Swift
Swift 服务端开发 Perfect、Vapor资料。
Stars: ✭ 123 (-3.15%)
Mutual labels:  vapor
Epochtalk
Next Generation Forum Software
Stars: ✭ 110 (-13.39%)
Mutual labels:  postgres
Calculate All
calculate_all method for aggregate functions in Active Record
Stars: ✭ 118 (-7.09%)
Mutual labels:  postgres
Flock
Automated deployment of Swift projects to servers
Stars: ✭ 127 (+0%)
Mutual labels:  vapor
Nextjs Pwa Graphql Sql Boilerplate
Next.js serverless PWA with GraphQL (Apollo) + Postgres SQL boilerplate
Stars: ✭ 125 (-1.57%)
Mutual labels:  postgres
Tunnel
PG数据同步工具(Java实现)
Stars: ✭ 122 (-3.94%)
Mutual labels:  postgres

Swift Linux Build Status macOS Build Status codecov GitHub license

PostgreSQL for Swift

Prerequisites

The PostgreSQL C driver must be installed in order to use this package.
Follow the README of the cpostgresql repo to get started.

Using PostgreSQL

This section outlines how to import the PostgreSQL package both with or without a Vapor project.

With Vapor

The easiest way to use PostgreSQL with Vapor is to include the PostgreSQL provider.

import PackageDescription

let package = Package(
    name: "Project",
    dependencies: [
        .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2),
        .Package(url: "https://github.com/vapor-community/postgresql-provider.git", majorVersion: 2)
    ],
    exclude: [ ... ]
)

The PostgreSQL provider package adds PostgreSQL to your project and adds some additional, Vapor-specific conveniences like drop.postgresql().

Using import PostgreSQLProvider will import both Fluent and Fluent's Vapor-specific APIs.

With Fluent

Fluent is a powerful, pure-Swift ORM that can be used with any Server-Side Swift framework. The PostgreSQL driver allows you to use a PostgreSQL database to power your models and queries.

import PackageDescription

let package = Package(
    name: "Project",
    dependencies: [
        ...
        .Package(url: "https://github.com/vapor/fluent.git", majorVersion: 2),
        .Package(url: "https://github.com/vapor-community/postgresql-driver.git", majorVersion: 2)
    ],
    exclude: [ ... ]
)

Use import PostgreSQLDriver to access the PostgreSQLDriver class which you can use to initialize a Fluent Database.

Just PostgreSQL

At the core of the PostgreSQL provider and PostgreSQL driver is a Swift wrapper around the C PostgreSQL client. This package can be used by itself to send raw, parameterized queries to your PostgreSQL database.

import PackageDescription

let package = Package(
    name: "Project",
    dependencies: [
        ...
        .Package(url: "https://github.com/vapor/postgresql.git", majorVersion: 2)
    ],
    exclude: [ ... ]
)

Use import PostgreSQL to access the PostgreSQL.Database class.

Examples

Connecting to the Database

import PostgreSQL

let postgreSQL =  PostgreSQL.Database(
    hostname: "localhost",
    database: "test",
    user: "root",
    password: ""
)

Select

let version = try postgreSQL.execute("SELECT version()")

Prepared Statement

The second parameter to execute() is an array of PostgreSQL.Values.

let results = try postgreSQL.execute("SELECT * FROM users WHERE age >= $1", [.int(21)])

Listen and Notify

try postgreSQL.listen(to: "test_channel") { notification in
    print(notification.channel)
    print(notification.payload)
}

// Allow set up time for LISTEN
sleep(1)

try postgreSQL.notify(channel: "test_channel", payload: "test_payload")

Connection

Each call to execute() creates a new connection to the PostgreSQL database. This ensures thread safety since a single connection cannot be used on more than one thread.

If you would like to re-use a connection between calls to execute, create a reusable connection and pass it as the third parameter to execute().

let connection = try postgreSQL.makeConnection()
let result = try postgreSQL.execute("SELECT * FROM users WHERE age >= $1", [.int(21)]), connection)

Contributors

Maintained by Steven Roebert, Nate Bird, Prince Ugwuh, and other members of the Vapor community.

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].