Esempio n. 1
0
    def __init__(self, config):
        self.config = config
        self.db = QKSQLAlchemy()
        self.db.configure(config)

        self.meta = {}
        self.base = {}

        self.templates = {}
        self._loadTemplates()
Esempio n. 2
0
import pprint
import sys
import zlib

import magic
import simplejson
import msgpack

from app_info import AppInfo

from qianka.sqlalchemy import QKSQLAlchemy


logger = logging.getLogger(__name__)

db = QKSQLAlchemy()
db.configure({
    'SQLALCHEMY_ECHO': False,
    'SQLALCHEMY_BINDS': {
        'default': {
            'adapter': 'mysql',
            'connector': 'mysqldb',
            'host': '127.0.0.1',
            'port': 3306,
            'user': '******',
            'pwd': '',
            'db': 'lppa',
        },
    }
})
Esempio n. 3
0
class SqlCodeGen(object):

    def __init__(self, config):
        self.config = config
        self.db = QKSQLAlchemy()
        self.db.configure(config)

        self.meta = {}
        self.base = {}

        self.templates = {}
        self._loadTemplates()

    def _loadTemplates(self):
        with open('column.tpl') as f:
            self.templates['column'] = jinja2.Template(f.read())

        with open('table.tpl') as f:
            self.templates['table'] = jinja2.Template(f.read())

    def reflect(self, tableName, bind):
        m = self.getMeta(bind)
        m.reflect(only=[tableName])
        base = self.getBase(bind, m)
        rv = base.classes.get(tableName)
        return rv

    def getMeta(self, bind):
        if bind in self.meta:
            return self.meta[bind]

        eng = self.db.get_engine(bind)
        m = MetaData(bind=eng)
        self.meta[bind] = m
        return m

    def getBase(self, bind, meta):
        if bind in self.base:
            return self.base[bind]
        base = automap_base(metadata=meta)
        base.prepare()
        self.base[bind] = base
        return base

    def autogen(self, tableName, bind='default'):
        model = self.reflect(tableName, bind)
        table = model.__table__

        # pprint.pprint(table.__dict__)

        staged = GenRoutine(table).engage()

        imports = staged['imports']
        tcol = self.templates['column']
        ttable = self.templates['table']

        columnContent = []
        for k, definition in staged['columns'].items():
            _ = ' ' * 4 + tcol.render(**definition)
            columnContent.append(_)
            # pprint.pprint(col.__dict__)
            # pprint.pprint(type(col.type))

        ctx = {
            'database': 'zhuanqian',
            'tableName': tableName,
            'columns': '\n'.join(columnContent),
            'import': ', '.join(sorted(imports)),
            'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        }

        rv = ttable.render(**ctx)
        return rv
# -*- coding: utf-8 -*-
import argparse
import logging
import lzma
import sys
import zlib

import magic

from qianka.sqlalchemy import QKSQLAlchemy

logger = logging.getLogger(__name__)

db = QKSQLAlchemy()
db.configure({
    'SQLALCHEMY_ECHO': False,
    'SQLALCHEMY_BINDS': {
        'default': {
            'adapter': 'mysql',
            'connector': 'mysqldb',
            'host': '127.0.0.1',
            'port': 3306,
            'user': '******',
            'pwd': '',
            'db': 'lppa',
        },
    }
})

db.configure({
    'SQLALCHEMY_ECHO': False,
Esempio n. 5
0
import argparse
import logging
import lzma
import pprint
import sys
import zlib

import magic
import msgpack
import simplejson

from qianka.sqlalchemy import QKSQLAlchemy

logger = logging.getLogger(__name__)

db = QKSQLAlchemy()
db.configure({
    'SQLALCHEMY_ECHO': False,
    'SQLALCHEMY_BINDS': {
        'default': {
            'adapter': 'mysql',
            'connector': 'mysqldb',
            'host': '127.0.0.1',
            'port': 3306,
            'user': '******',
            'pwd': '',
            'db': 'lppa',
        },
    }
})
Esempio n. 6
0
# -*- coding: utf-8 -*-
from flask import Config

from qianka.sqlalchemy import QKSQLAlchemy
db = QKSQLAlchemy()

config = Config('.')

config.from_pyfile('config.py')

db.configure(config)
Esempio n. 7
0
import sys

import flask.config
from flask_cors import CORS

from qianka.flaskext import QKFlask
from qianka.flaskext.sqlalchemy import QKFlaskSQLAlchemy
from qianka.sqlalchemy import QKSQLAlchemy

from .util import load_module_recursively

from qianka.cache import QKCache

cache = QKCache()
# database
db = QKSQLAlchemy()

APP_PATH = abspath(dirname(__file__))
ROOT_PATH = abspath(dirname(APP_PATH))


class Application(QKFlask):
    def __init__(self):
        super(Application, self).__init__(__name__, static_folder='../static')

        # 加载配置文件
        self.load_config()

        # 配置日志
        self.setup_logging()