Пример #1
0
from config import LocalConfig
from elixir import metadata, session
from flask import Flask, g

app = Flask(__name__)
app.config.from_object(LocalConfig)
# DB configuration
metadata.bind = app.config['SQLALCHEMY_DATABASE_URI']
metadata.echo = True

session.configure(autoflush=False)

from flask import Response
from flask import json, send_file, request, request_started

## REQUESTS

@app.before_request
def option_autoreply():
    """ Always reply 200 on OPTIONS request """

    set_pagination_infos(request.values)

    if request.method == 'OPTIONS':
        resp = app.make_default_options_response()

        headers = None
        if 'ACCESS_CONTROL_REQUEST_HEADERS' in request.headers:
            headers = request.headers['ACCESS_CONTROL_REQUEST_HEADERS']
Пример #2
0
try:
    from sqlalchemy import orm

    # ``sqlalchemy.orm.ScopedSession`` is needed by ``elixir``
    orm.__dict__.setdefault('ScopedSession', orm.scoped_session)

    session = orm.scoped_session(orm.sessionmaker())
except ImportError:
    pass

try:
    from elixir import setup_all, session
except ImportError:
    pass

session.configure(autoflush=True, expire_on_commit=True, autocommit=True)
query = session.query

# -----------------------------------------------------------------------------

def entity_getstate(entity):
    """Return the state of an SQLAlchemy entity

    In:
      - ``entity`` -- the SQLAlchemy entity

    Return:
      - the state dictionary
    """
    state = entity._sa_instance_state   # SQLAlchemy managed state
Пример #3
0
    name = Field(String(255), default='')

class IdeaMessage(Entity):
    using_options(tablename='idea_message')

    id = Field(Integer, primary_key=True)
    description = Field(Text, default='')
    status = Field(Integer, default=0)
    #sender
    sender_id = Field(Integer, default=0)
    #receiver
    send_time = Field(DateTime, default=datetime.datetime.now)
    idea_id = Field(Integer, default=0)

DB_USER = '******'
DB_PASS = '******'
HOST = '**'
DB_DATA = '**'
db_str = 'mysql://%s:%s@%s/%s' % (DB_USER, DB_PASS, HOST, DB_DATA)

engine = create_engine(db_str, isolation_level="READ UNCOMMITTED", pool_size=1000)

session.configure(bind=engine)
metadata.bind = engine
metadata.bind.echo = False
setup_all(False)

def flush():
	session.commit()
	session.flush()
Пример #4
0
    # ``sqlalchemy.orm.ScopedSession`` is needed by ``elixir``
    orm.__dict__.setdefault('ScopedSession', orm.scoped_session)

    session = orm.scoped_session(orm.sessionmaker())
except ImportError:
    pass


try:
    from elixir import setup_all, session  # noqa: F811
except ImportError:
    pass


session.configure(autoflush=True, expire_on_commit=True, autocommit=True)
query = session.query


# -----------------------------------------------------------------------------

def entity_getstate(entity):
    """Return the state of an SQLAlchemy entity

    In:
      - ``entity`` -- the SQLAlchemy entity

    Return:
      - the state dictionary
    """
    state = entity._sa_instance_state  # SQLAlchemy managed state
Пример #5
0
    id = Field(Integer, primary_key=True)
    description = Field(Text, default='')
    status = Field(Integer, default=0)
    #sender
    sender_id = Field(Integer, default=0)
    #receiver
    send_time = Field(DateTime, default=datetime.datetime.now)
    idea_id = Field(Integer, default=0)


DB_USER = '******'
DB_PASS = '******'
HOST = '**'
DB_DATA = '**'
db_str = 'mysql://%s:%s@%s/%s' % (DB_USER, DB_PASS, HOST, DB_DATA)

engine = create_engine(db_str,
                       isolation_level="READ UNCOMMITTED",
                       pool_size=1000)

session.configure(bind=engine)
metadata.bind = engine
metadata.bind.echo = False
setup_all(False)


def flush():
    session.commit()
    session.flush()