def setup(app): global alchemy, session if alchemy is None: setup_uri(app, use_db_name=False) setup_settings(app) alchemy = _SQLAlchemy(app, ) session = alchemy.session create_database_if_not_exists(app.config) setup_uri(app, use_db_name=True) else: raise RuntimeError('Database already initialized')
from flask_sqlalchemy import SQLAlchemy as _SQLAlchemy from flask_security import Security as _Security db = _SQLAlchemy() security = _Security() from .game import Game from .role import Role from .tables import roles_users from .user import User def _populate__all__(lcls): global __all__ import inspect as _inspect __all__ = sorted(name for name, obj in lcls.items() if not (name.startswith('_') or _inspect.ismodule(obj))) _populate__all__(locals())
try: yield self.session.commit() except Exception as e: self.session.rollback() raise e class Query(BaseQuery): def filter_by(self, **kwargs): if 'status' not in kwargs.keys(): kwargs['status'] = 1 super(Query, self).filter_by(**kwargs) db = _SQLAlchemy() class Base(db.Model): __abstract__ = True create_time = Column('create_time', Integer) status = Column(SmallInteger, default=1) def __init__(self): self.create_time = int(datetime.now().timestamp()) def set_attrs(self, attrs_dict): for key, value in attrs_dict.items(): if hasattr(self, key) and key != 'id': setattr(self, key, value)
from rasterio.warp import transform from rasterio.features import rasterize from rasterio.transform import from_bounds import mercantile from supermercado import burntiles from flask import Flask, request, Response, jsonify from flask_sqlalchemy import SQLAlchemy as _SQLAlchemy, BaseQuery import pymongo import json # connect postgresql SQLALCHEMY_DATABASE_URI = 'postgres+psycopg2://postgres:[email protected]/quhua_data' app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI db = _SQLAlchemy(app) # connect mongodb myclient = pymongo.MongoClient("mongodb://127.0.0.1:27017/tile_donwloader") myMongo = myclient["tile_donwloader"] def queryBySQL(sql): return db.session.execute(sql) @app.route('/') def hello_world(): return 'http://localhost:5004/cover?area_code=&zoom=&collection=&tile_type=image/vector'
# # This file is part of BDC-DB. # Copyright (C) 2020 INPE. # # BDC-DB is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. # """Database instance using Flask-SQLAlchemy extension.""" from flask_sqlalchemy import SQLAlchemy as _SQLAlchemy from sqlalchemy import MetaData as _MetaData # See more in https://docs.sqlalchemy.org/en/13/core/constraints.html#configuring-constraint-naming-conventions NAMING_CONVENTION = { "ix": 'idx_%(column_0_label)s', "uq": "%(table_name)s_%(column_0_name)s_key", "ck": "%(table_name)s_%(constraint_name)s_ckey", "fk": "%(table_name)s_%(column_0_name)s_%(referred_table_name)s_fkey", "pk": "%(table_name)s_pkey" } """Naming convention for SQLAlchemy constraint keys""" metadata = _MetaData(naming_convention=NAMING_CONVENTION) """Default database metadata object holding associated schema constructs.""" db = _SQLAlchemy(metadata=metadata) """Shared database instance using Flask-SQLAlchemy extension."""