GithubHelp home page GithubHelp logo

madingsgsj001 / postgresql-provider Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vapor-community/postgresql-provider

0.0 1.0 0.0 41 KB

PostgreSQL Provider for the Vapor web framework.

License: MIT License

Swift 100.00%

postgresql-provider's Introduction

Swift Linux Build Status macOS Build Status codecov GitHub license

PostgreSQL Provider for Vapor

Adds PostgreSQL support to the Vapor web framework.

Prerequisites

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

Setup

Note that the process is different for Swift 3 and 4.

  1. Add the dependency to project

    • Swift 3: add to Package.swift package dependencies
      .Package(url: "https://github.com/vapor-community/postgresql-provider.git", majorVersion: 2, minor: 1)
    • Swift 4: add to Package.swift package and target dependencies
      .package(url: "https://github.com/vapor-community/postgresql-provider.git", .upToNextMajor(from: "2.1.0"))
      // ...
      .target(name: "App", dependencies: ["Vapor", "FluentProvider", "PostgreSQLProvider"], ...)
  2. Fetch dependencies and regenerate the Xcode project

    vapor update

Usage

import Vapor
import PostgreSQLProvider

let config = try Config()
try config.addProvider(PostgreSQLProvider.Provider.self)

let drop = try Droplet(config)

Configure Fluent

Once the provider is added to your Droplet, you can configure Fluent to use the PostgreSQL driver.

Config/fluent.json

  "driver": "postgresql"

Configure PostgreSQL

Basic

Here is an example of a simple PostgreSQL configuration file.

Config/secrets/postgresql.json

{
    "hostname": "127.0.0.1",
    "user": "postgres",
    "password": "hello",
    "database": "test",
    "port": 5432
}

Alternatively, you can set a url with the configuration parameters.

Config/secrets/postgresql.json

{
    "url": "psql://user:pass@hostname:5432/database"
}

Read Replicas

Read replicas can be supplied by passing a single master hostname and an array of readReplicas hostnames.

Config/secrets/postgresql.json

{
    "master": "master.postgresql.foo.com",
    "readReplicas": ["read01.postgresql.foo.com", "read02.postgresql.foo.com"],
    "user": "postgres",
    "password": "hello",
    "database": "test",
    "port": 5432
}

Driver

You can get access to the PostgreSQL Driver on the droplet.

import Vapor
import PostgreSQLProvider

let postgresqlDriver = try drop.postgresql()

postgresql-provider's People

Contributors

natebird avatar vzsg avatar gperdomor avatar prince2k3 avatar mludi avatar tanner0101 avatar sroebert avatar calebkleveter avatar mcritz avatar balestrapatrick avatar pruthvikar avatar slk333 avatar

Watchers

James Cloos 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.