Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions active_alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@

utcnow = arrow.utcnow


def _create_scoped_session(db, query_cls):
session = sessionmaker(autoflush=True, autocommit=False,
bind=db.engine, query_cls=query_cls)
return scoped_session(session)


def _tablemaker(db):
def make_sa_table(*args, **kwargs):
if len(args) > 1 and isinstance(args[1], db.Column):
Expand Down Expand Up @@ -103,6 +105,7 @@ class ModelTableNameDescriptor(object):
"""
Create the table name if it doesn't exist.
"""

def __get__(self, obj, type):
tablename = type.__dict__.get('__tablename__')
if not tablename:
Expand Down Expand Up @@ -196,7 +199,6 @@ def update(self, **kwargs):
self.save()
return self


@classmethod
def query(cls, *args):
"""
Expand Down Expand Up @@ -234,6 +236,7 @@ def delete(self, delete=True, hard_delete=False):
self.db.rollback()
raise


class Model(BaseModel):
"""
Model create
Expand Down Expand Up @@ -270,9 +273,9 @@ def get(cls, id, include_deleted=False):
:param id: The id of the entry
:param include_deleted: It should not query deleted record. Set to True to get all
"""
return cls.query(include_deleted=include_deleted)\
.filter(cls.id == id)\
.first()
return cls.query(include_deleted=include_deleted) \
.filter(cls.id == id) \
.first()

def delete(self, delete=True, hard_delete=False):
"""
Expand Down Expand Up @@ -341,7 +344,8 @@ def __init__(self, uri='sqlite://',
pool_timeout=None,
pool_recycle=None,
convert_unicode=True,
query_cls=BaseQuery):
query_cls=BaseQuery,
connect_args={}):

self.uri = uri
self.info = make_url(uri)
Expand All @@ -351,6 +355,7 @@ def __init__(self, uri='sqlite://',
pool_timeout=pool_timeout,
pool_recycle=pool_recycle,
convert_unicode=convert_unicode,
connect_args=connect_args
)

self.connector = None
Expand Down