예제 #1
0
def create_connection():
    return pymysql.connect(host=db_credentials.get("host"),
                           user=db_credentials.get("username"),
                           password=db_credentials.get("password"),
                           db=db_credentials.get("db"),
                           charset='utf8mb4',
                           cursorclass=pymysql.cursors.DictCursor)
예제 #2
0
def load_chains():
    chains = {}
    index = db.get('index')
    for entry in index:
        words = db.get(entry)
        pair = tuple(entry.split())
        chains[pair] = words
    return chains
예제 #3
0
def load_chains():
	chains = {}
	index = db.get('index')
	for entry in index:
		words = db.get(entry)
		pair = tuple(entry.split())
		chains[pair] = words
	return chains
예제 #4
0
def get_connection_string():
    if db.get('type') == 'mysql':
        settings = db.get('mysql')
        host = settings.get('host')
        user = settings.get('user')
        db_name = settings.get('db_name')
        password = settings.get('pass')

        return "mysql://%s:%s@%s/%s?charset=utf8" % (user, password, host, db_name)

    elif db.get('type') == 'sqlite':
        return "sqlite:///memory"
예제 #5
0
def run(web):
    post_id = web.sub_path[1:]

    if not post_id: return error(404, "Not Found")

    web.post = db.get('post', by_id=post_id)

    if web.post:
        return render('show_post.html', web)
    else:
        return error(404, "Not Found")
예제 #6
0
def run(web):
    post_id = web.sub_path[1:]

    if not post_id: return error(404, "Not Found")

    web.post = db.get('post', by_id=post_id)

    if web.post:
        return render('show_post.html', web)
    else:
        return error(404, "Not Found")
예제 #7
0
def get_user(user_id):
    """根据id获取用户"""
    sql = "select * from user where id = %s;"
    user = db.get(sql, user_id)
    return user
예제 #8
0
def checkout_login(phone, password):
    """先只支持手机号码登录吧"""
    sql = "select id from user where phone = %s and password = %s;"
    user_id = db.get(sql, phone, password)
    return user_id["id"] if user_id else 0
예제 #9
0
def getEngr101():
    selfUrl = "asbarber.us/engr101"
    url = db.get('engr101').get('url')
    return flask.render_template("engr101/engr101.html",
                                 url=url,
                                 selfUrl=selfUrl)
예제 #10
0
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool
import datetime

from config import db

DeclarativeBase = declarative_base()

db_url = "mysql+pymysql://%s:%s@%s/%s?charset=UTF8MB4" % (
    db.get('username'), db.get('password'), db.get('host'), db.get('db'))


def db_connect():
    '''Create connection to database'''
    return create_engine(db_url, encoding='utf-8', poolclass=NullPool)


def create_db_session(engine):
    '''Create session with database'''
    Session = sessionmaker(bind=engine, autoflush=False)
    session = Session()
    return session


Base = declarative_base()
metadata = Base.metadata


class powerData(Base):
예제 #11
0
def get_engine():
    return create_engine(get_connection_string(), echo=db.get('echo'))
예제 #12
0
def get_user(user_id):
    """根据id获取用户"""
    sql = "select * from user where id = %s;"
    user = db.get(sql, user_id)
    return user
예제 #13
0
def checkout_login(phone, password):
    """先只支持手机号码登录吧"""
    sql = "select id from user where phone = %s and password = %s;"
    user_id = db.get(sql, phone, password)
    return user_id["id"] if user_id else 0