Пример #1
0
 def __init__(self):
     pg_simple.config_pool(max_conn=db_config.max_conn,
                             expiration=db_config.expiration,
                             host=db_config.host,
                             port=db_config.port,
                             database=db_config.database,
                             user=db_config.user,
                             password=db_config.password)
     self.schema = db_config.schema
Пример #2
0
    def setUp(self):
        super(AbstractPgSimpleTestCase, self).setUp()
        pg_simple.config_pool(max_conn=25,
                              expiration=5,
                              pool_manager=self._get_pool_manager(),
                              dsn=TEST_DB_DSN)

        self.tables = (('pg_t1', '''id SERIAL PRIMARY KEY,
                                   name TEXT NOT NULL,
                                   count INTEGER NOT NULL DEFAULT 0,
                                   active BOOLEAN NOT NULL DEFAULT true'''),
                       ('pg_t2', '''id SERIAL PRIMARY KEY,
                                   value TEXT NOT NULL,
                                   pg_t1_id INTEGER NOT NULL REFERENCES pg_t1(id)'''))
Пример #3
0
 def __init__(self, db_config):
     if self.__instance__ is not None:
         raise Exception("Can't create other instance")
     self.connection_pool = pg_simple.config_pool(
         max_conn=250,
         expiration=60,
         pool_manager=ThreadedConnectionPool,
         dsn=db_config["db_connection_string"])
     self.config = db_config
     self.__instance__ = self
Пример #4
0
    def setUp(self):
        super(AbstractPgSimpleTestCase, self).setUp()
        self.pool = pg_simple.config_pool(max_conn=25,
                              expiration=5,
                              pool_manager=self._get_pool_manager(),
                              dsn=TEST_DB_DSN)

        self.tables = (('pg_t1', '''id SERIAL PRIMARY KEY,
                                   name TEXT NOT NULL,
                                   count INTEGER NOT NULL DEFAULT 0,
                                   active BOOLEAN NOT NULL DEFAULT true'''),
                       ('pg_t2', '''id SERIAL PRIMARY KEY,
                                   value TEXT NOT NULL,
                                   pg_t1_id INTEGER NOT NULL REFERENCES pg_t1(id)'''))
Пример #5
0
import pg_simple
from config import host, port, database

pool = pg_simple.config_pool(host=host,
                             port=port,
                             database=database,
                             user="******",
                             password="******")

# logging in uses it's own initialization of PgSimple, this one is left for
# `stats`. `login` page needs to reestablish connection after logging out, but
# `stats` gets it only once and it doesn't get cleared in the meantime. `login`
# one does though, because it gets the session cleared?
db = pg_simple.PgSimple()

# insert into data (datetime, download, upload, ping, api, ip, provider) values ('2017-09-20 22:50:40', 31.29, 2.78, 22.371, '3', '109.173.147.181', 'INEA');
Пример #6
0
from dispatcher import Dispatcher
from jinjasql import JinjaSql

QUEUES = {}
RESULT_QUEUE = multiprocessing.Queue()


def ENV(val):
    return os.environ[val]


CONNECTION_POOL = pg_simple.config_pool(
    max_conn=50,
    expiration=60,
    host=ENV('DATABASE_HOST'),
    port=ENV('DATABASE_PORT'),
    database=ENV('DATABASE_NAME'),
    user=ENV('DATABASE_USER'),
    pool_manager=pg_simple.pool.ThreadedConnectionPool,
    password=ENV('DATABASE_PASSWORD'))


def buildquery(host, start_time, end_time):
    template = '''
    select
        time_bucket('1 minute', ts) AS period
        , min(usage) AS min_cpu_usage
        , max(usage) AS max_cpu_usage
    from
        cpu_usage
    where
Пример #7
0
# -*- coding: utf-8 -*-
"""Main module."""
from os.path import dirname
import logging.config
import bottle
import pg_simple

from services import *

#logging.config.fileConfig("{}/{}".format(dirname(__file__), 'logging.ini'))
logging.config.fileConfig("logging.ini")

with open("database.conf") as config_file:
    pg_simple.config_pool(dsn=config_file.readlines()[0])

app = bottle.default_app()

if __name__ == "__main__":
    dev_options = {
        'host': '0.0.0.0',
        'port': 8000,
        'workers': 1,
        'reload': True,
        'debug': True
    }
    bottle.run(**dev_options)
Пример #8
0
import pg_simple
import sys
import datetime

connection_pool = pg_simple.config_pool(
    database='wms',
    host='localhost',
    port='54321',
    user='******',
    password='******',
    expiration=120)  # idle timeout = 120 seconds

db = pg_simple.PgSimple(connection_pool,
                        log=sys.stdout,
                        log_fmt=lambda x: '>> %s' %
                        (x if isinstance(x, str) else x.query),
                        nt_cursor=True)

# dropping and creating tables
db.drop('books')

db.create(
    'books', '''
"id" SERIAL NOT NULL,
"genre" VARCHAR(20) NOT NULL,
"name" VARCHAR(40) NOT NULL,
"price" MONEY NOT NULL,
"published" DATE NOT NULL,
"modified" TIMESTAMP(6) NOT NULL DEFAULT now()
''')