Git Product home page Git Product logo

pgmagic's Introduction

pgmagic

Postgres connector for sqlalchemy

Features

  • Multiple databases
  • Loading configuration from environment

Installation

$ pip install -e git+https://github.com/robodorm/pgmagic.git#egg=pgmagic --upgrade

Example usage

docker-compose.yml:

version: '2'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      # optional, "PG" - already set as a default prefix
      # Prefix is important, because ALL env vars with that prefix will be
      # loaded into the configuration
      PGM_PREFIX: PG
      
      # Define the database with the name "default". Name used in the
      # configuration to access the database.
      PG_PASSWORD: db_one
      PG_USER: db_one
      PG_DB: db_one
      PG_HOST: db_one

      # Definition of a second database with name "TWO". Name could be any.
      # All missed parameters will be set to defaults*
      PG_HOST_TWO: db_two
    links:
      - db_one
      - db_two
    restart: always

  db_one:
    image: postgres:latest
    environment:
      POSTGRES_PASSWORD: db_one
      POSTGRES_USER: db_one
      POSTGRES_DB: db_one
  db_two:
    image: postgres:latest
    environment:
      POSTGRES_PASSWORD: db_two
      POSTGRES_USER: db_two
      POSTGRES_DB: db_two

*defaults:

"PASSWORD": "postgres",
"USER": "postgres",
"DB": "postgres",
"HOST": "postgres",
"PORT": 5432

app.py:

from pgmagic import get_base, session

# default model DB is "default"
class DataModelOne(get_base()):
    __tablename__ = 'data'
    id = Column(Integer, primary_key=True)

# copy record from "default" to "db_two"
with session("TWO") as s:
        s.add(DataModelOne.query.filter(DataModelOne.id = 1).first())

(!) Project is not well tested yet (!!!)

pgmagic's People

Contributors

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