Skip to content

Commit

Permalink
model/base: Move code into "database" and "search" modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed May 9, 2015
1 parent 640ed20 commit c87c2a7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 30 deletions.
23 changes: 23 additions & 0 deletions skylines/database.py
@@ -1,3 +1,26 @@
from flask.ext.sqlalchemy import SQLAlchemy


def query(cls, **kw):
q = db.session.query(cls)

if kw:
q = q.filter_by(**kw)

return q


def get(cls, id):
return cls.query().get(id)


def exists(cls, **kw):
return cls.query(**kw).first() is not None


db = SQLAlchemy(session_options=dict(expire_on_commit=False))

db.Model.flask_query = db.Model.query
db.Model.query = classmethod(query)
db.Model.get = classmethod(get)
db.Model.exists = classmethod(exists)
3 changes: 0 additions & 3 deletions skylines/model/__init__.py
Expand Up @@ -2,9 +2,6 @@

# flake8: noqa

import skylines.model.base

# Import your model modules here.
from .aircraft_model import AircraftModel
from .airport import Airport
from .airspace import Airspace
Expand Down
27 changes: 0 additions & 27 deletions skylines/model/base.py

This file was deleted.

2 changes: 2 additions & 0 deletions skylines/model/search.py
Expand Up @@ -69,6 +69,8 @@ def search_query(cls, tokens,

return query

db.Model.search_query = classmethod(search_query)


def combined_search_query(models, tokens, include_misses=False, ordered=True):
models, tokens = process_type_option(models, tokens)
Expand Down

0 comments on commit c87c2a7

Please sign in to comment.