How to use the pypistats.extensions.db.Integer function in pypistats

To help you get started, we’ve selected a few pypistats examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crflynn / pypistats.org / pypistats / database.py View on Github external
class Model(CRUDMixin, db.Model):
    """Base model class that includes CRUD convenience methods."""

    __abstract__ = True


class SurrogatePK(object):
    """A mixin that adds a surrogate integer "primary key" column.

    Adds a surrogate integer "primary key" column named ``id`` to any
    declarative-mapped class.
    """

    __table_args__ = {"extend_existing": True}

    id = Column(db.Integer, primary_key=True)

    @classmethod
    def get_by_id(cls, record_id):
        """Get record by ID."""
        if any(
                (isinstance(record_id, basestring) and record_id.isdigit(),
                 isinstance(record_id, (int, float))),
        ):
            return cls.query.get(int(record_id))
        return None
github crflynn / pypistats.org / pypistats / models / user.py View on Github external
from pypistats.database import Column
from pypistats.database import Model
from pypistats.database import SurrogatePK
from pypistats.extensions import db


MAX_FAVORITES = 20


class User(UserMixin, SurrogatePK, Model):
    """A user of the app."""

    __tablename__ = 'users'

    uid = Column(db.Integer(), unique=True)
    username = Column(db.String(39), nullable=False)
    avatar_url = Column(db.String(256))
    token = Column(db.String(256))
    created_at = \
        Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
    active = Column(db.Boolean(), default=False)
    is_admin = Column(db.Boolean(), default=False)
    favorites = Column(ARRAY(db.String(128), dimensions=1))

    def __init__(self, token, **kwargs):
        """Create instance."""
        db.Model.__init__(self, token=token, **kwargs)

    def __repr__(self):
        """Represent instance as a unique string."""
        return f""
github crflynn / pypistats.org / pypistats / models / download.py View on Github external
f"{str(self.date)} - {str(self.package)} - {str(self.category)}"
        )


class PythonMajorDownloadCount(Model):
    """Download counts by python major version."""

    __tablename__ = "python_major"

    date = Column(db.Date, primary_key=True, nullable=False)
    package = Column(
        db.String(128), primary_key=True, nullable=False, index=True
    )
    # python_major version, 2 or 3 (or null)
    category = Column(db.String(4), primary_key=True, nullable=True)
    downloads = Column(db.Integer(), nullable=False)

    def __repr__(self):
        return "
github crflynn / pypistats.org / pypistats / models / download.py View on Github external
from pypistats.database import Model
from pypistats.extensions import db


class OverallDownloadCount(Model):
    """Overall download counts."""

    __tablename__ = "overall"

    date = Column(db.Date, primary_key=True, nullable=False)
    package = Column(
        db.String(128), primary_key=True, nullable=False, index=True
    )
    # with_mirrors or without_mirrors
    category = Column(db.String(16), primary_key=True, nullable=False)
    downloads = Column(db.Integer(), nullable=False)

    def __repr__(self):
        return "