예제 #1
0
def get_item(type: str, id: int):
    return db.get_instance(type, id)
예제 #2
0
파일: test.py 프로젝트: takirohit/Utils
import database

if __name__ == "__main__":
	try:
		db = database.get_instance(YOUR_DB_HOST, YOUR_DB_USER, YOUR_DB_PASSWORD, YOUR_DB_NAME)
		db.get_columns(YOUT_TABLE_NAME, datatype=dict)
	except Exception, e:
		print str(e)
		exit

예제 #3
0
from flask import Flask
from flask_restful import Resource, Api
from flask_cors import CORS
from psycopg2.extensions import AsIs
import database

app = Flask(__name__)
CORS(app)
api = Api(app)

db = database.get_instance()

class Count(Resource):
  def get(self, attribute):
    if attribute not in ['weapon', 'neighborhood', 'district', 'premise', 'inside']:
      return {'error': 'Invalid attribute'}

    cur = db.cursor()
    stmt = 'SELECT %s, COUNT(*) FROM crimes WHERE %s IS NOT NULL GROUP BY %s ORDER BY COUNT(*) DESC'
    cur.execute(stmt, (AsIs(attribute), AsIs(attribute), AsIs(attribute)))

    results = []
    for row in cur.fetchall():
      results.append({'attribute': row[0], 'count': row[1]})

    return {'count': results}

class Coordinates(Resource):
  def get(self):
    cur = db.cursor()
    cur.execute('SELECT longitude, latitude FROM crimes;')
예제 #4
0
def get_dbfs():
    configuration = config.parse('config.toml')
    db = database.get_instance(configuration)
    fs = filesystem.get_instance(configuration)
    return (db, fs)