(self, db, **kwargs)
return self.link
Find by filter params. Order of query_dict is important. In case
        of query by `long_url` first calculate crc32 hash and query it before
        long_url query for performance optimization.
Find by filter params. Order of query_dict is important. In case
        of query by `long_url` first calculate crc32 hash and query it before
        long_url query for performance optimization.
Find by filter params . Order of query_dict is important . In case of query by long_url first calculate crc32 hash and query it before long_url query for performance optimization .
def find(self, db, **kwargs):
        """Find by filter params. Order of query_dict is important. In case
        of query by `long_url` first calculate crc32 hash and query it before
        long_url query for performance optimization.
        """
        query_dict = dict()
        long_url = kwargs.get('long_url')
        if long_url:
            if not urlparse(long_url).scheme:
                long_url = 'http://{}'.format(long_url)
            query_dict['long_url_hash'] = self.crc32(long_url)
            query_dict['long_url'] = long_url
        query_dict.update(self.build_query_dict(**kwargs))
        # build sqlalchmey and query
        query = [getattr(Link, k) == v for k, v in query_dict.items()]
        url = db.query(Link).filter(and_(*query))
        # q = str(
        # url.statement.compile(compile_kwargs={"literal_binds": True}))
        if url.count() < 1:
            return None
        # TODO: handle multiple in case of empty query dict
        self.link = url.one()
        return self.link
def find ( self , db , * * kwargs ) : query_dict = dict ( ) long_url = kwargs . get ( 'long_url' ) if long_url : if not urlparse ( long_url ) . scheme : long_url = 'http://{}' . format ( long_url ) query_dict [ 'long_url_hash' ] = self . crc32 ( long_url ) query_dict [ 'long_url' ] = long_url query_dict . update ( self . build_query_dict ( * * kwargs ) ) # build sqlalchmey and query query = [ getattr ( Link , k ) == v for k , v in query_dict . items ( ) ] url = db . query ( Link ) . filter ( and_ ( * query ) ) # q = str( # url.statement.compile(compile_kwargs={"literal_binds": True})) if url . count ( ) < 1 : return None # TODO: handle multiple in case of empty query dict self . link = url . one ( ) return self . link