Пример #1
0
class InvoiceTemplate(InvoiceBase, Base):
    __tablename__ = "templates"
    name = Column(String(50), primary_key=True)
    description = Column(String(200))
    template = Column(String(500))
    invoices = relationship("Invoice", back_populates="template")
    timesheets = relationship("Timesheet", back_populates="template")
    letterhead = Column(BLOB(1024 * 1024))

    @property
    def taxes(self):
        data = yaml.load(self.template)
        return data.get('taxes', {})

    @property
    def fields(self):
        data = yaml.load(self.template)
        return [x.strip() for x in data['rows'].strip().strip("|").split("|")]

    @property
    def footers(self):
        data = yaml.load(self.template)
        footer_rows = data['footer'].strip().split("\n")
        return [[t.strip() for t in x.strip("|").split("|")]
                for x in footer_rows]
Пример #2
0
class FileInfo(Base):
    __tablename__ = 'file_infos'
    id = Column(Integer, primary_key=True)
    filepath = Column(String(128), nullable=False)
    filename = Column(String(128), nullable=False)

    organized = Column(Boolean, unique=False, default=False)

    vector = deferred(Column(BLOB(250000), nullable=False))

    cluster_id = Column(Integer, ForeignKey("clusters.id"), nullable=True)
    cluster = relationship("Cluster")

    def __str__(self):
        return 'File named: {} assigned to cluster: {}'.format(self.filename, self.cluster_id)

    def set_vector(self, coeffs):
        c = coeffs.todense()
        out = io.BytesIO()
        np.save(out, c)
        out.seek(0)
        self.vector = sqlite3.Binary(out.read())

    def calc_distance(self, other_coefficients):
        distance = self.get_vector().dot(other_coefficients.transpose())
        return distance

    def get_vector(self):
        out = io.BytesIO(self.vector)
        out.seek(0)
        output = np.load(out).astype(float64)
        sparse_output = csr_matrix(output)
        return sparse_output
Пример #3
0
def access():
    meta = MetaData()
    access = Table('access', meta, Column('username', String(32)),
                   Column('password', String(256)),
                   Column('campaigns', BLOB(64000)),
                   Column('roles', String(128)))
    return meta, access
Пример #4
0
class announce_manager(formInfomation):
    __tablename__ = 'announce_manager'
    announce_id = Column(String(12), primary_key=True)
    stock_code = Column(String(10))
    title = Column(BLOB())
    announce_timestamp = Column(Integer)
    url = Column(String(100))
    announce_type = Column(String(20))
Пример #5
0
class ConferenceCallChunk(Base):
    __tablename__ = 'conference_call_chunks'
    call_reference = Column(String(10), nullable=False)
    index = Column(Integer(), nullable=False)
    total = Column(Integer(), nullable=False)
    filepath = Column(String(), nullable=False, unique=True, primary_key=True)
    url = Column(String(), nullable=False, unique=True)
    data = Column(BLOB(), nullable=True, unique=True)
Пример #6
0
def campaign():
    meta = MetaData()
    campaign = Table('campaign', meta, Column('acid', String(16)),
                     Column('record', String(32)),
                     Column('module', String(48)),
                     Column('timestamp', String(32)), Column('job', String(8)),
                     Column('campaign', String(64)),
                     Column('output', BLOB(64000)))
    return meta, campaign
Пример #7
0
class DBWebExtHttpResponseContent(Base):
    __tablename__ = 'http_response_content'

    id = Column(Integer(), primary_key=True, auto_increment=True)
    content_hash = Column(Text(), nullable=False)
    content = Column(
        BLOB(), nullable=False
    )  # noqa This should store at least 1GB (https://stackoverflow.com/questions/11737955/what-is-the-maximum-size-of-the-image-to-be-stored-as-blob-in-sqlite-database)
    length = Column(Integer(), nullable=False)
Пример #8
0
def build():
    meta = MetaData()
    data = Table('build', meta, Column('ctrlKey', String(64)),
                 Column('distKey', String(64)), Column('ccKey', String(64)),
                 Column('password', String(128)), Column('acid', String(16)),
                 Column('confKey', String(64)), Column('pkgCore', BLOB(8000)),
                 Column('tempAcid', String(16)),
                 Column('regPass', String(128)), Column('regKey', String(16)),
                 Column('tcKey', String(64)), Column('campaign', String(128)))
    return meta, data
Пример #9
0
def metadata():
    meta = MetaData()
    data = Table('metadata', meta, Column('acid', String(16)),
                 Column('hostname', String(32)), Column('ip', BLOB(4096)),
                 Column('os', String(32)), Column('arch', String(16)),
                 Column('integrity', String(8)), Column('user', String(32)),
                 Column('cwd', String(64)), Column('domain', String(64)),
                 Column('registered', String(32)),
                 Column('status', String(16)))
    return meta, data
Пример #10
0
class User(db.Model):
    __tablename__ = 'user'
    id = Id()
    email = Column(String(256), nullable=False, unique=True)
    password = Column(BLOB(60), nullable=False)
    email_confirmed = Column(Boolean(), nullable=False, default=False)

    def to_dict(self):
        return {
            'id': self.id,
            'email': self.email,
            'email_confirmed': self.email_confirmed
        }
Пример #11
0
class Cluster(Base):
    __tablename__ = 'clusters'

    id = Column(Integer, primary_key=True)

    center = deferred(Column(BLOB(250000), nullable=False))

    def __init__(self, center_vector):
        self.set_center(center_vector)

    def get_center(self):
        out = io.BytesIO(self.center)
        out.seek(0)
        output = np.load(out).astype(float64)
        sparse_output = csr_matrix(output)
        return sparse_output

    def set_center(self, coeffs):
        out = io.BytesIO()
        np.save(out, coeffs)
        out.seek(0)
        self.center = sqlite3.Binary(out.read())
Пример #12
0
class Item(Base):

    __tablename__ = 'item'

    item_id = Column('item_id', Integer, primary_key=True)
    user_id = Column('user_id',
                     Integer,
                     ForeignKey('user.user_id'),
                     nullable=False)
    warehouse_id = Column('warehouse_id',
                          Integer,
                          ForeignKey('warehouse.warehouse_id'),
                          nullable=False)
    name = Column('name', String(32), nullable=False)
    description = Column('description', BLOB(8192), nullable=True)
    barcode = Column('barcode', String(64), index=True, nullable=True)
    available = Column('available', Integer, default=0)
    allocated = Column('allocated', Integer, default=0)
    alert = Column('alert', Integer, default=0)
    created_at = Column('created_at', Integer, default=int(time()))

    __table_args__ = (UniqueConstraint('warehouse_id',
                                       'barcode',
                                       name='barcode_warehouse_unique'), )
Пример #13
0
class proc_WorkspaceSettings(Base, BaseMixin):
    '''
        settings is a yaml blob
    '''
    settings = BLOB()
Пример #14
0
class hs_device_logs(hsBase, Base):
    type = Column(Integer)
    logs = Column(BLOB())
Пример #15
0
class User(Base):
    __tablename__ = 'user'
    id = Column(Integer(), primary_key=True)
    name = Column(String(50))
    email = Column(String(127), unique=True)
    password = Column(BLOB())
Пример #16
0
                   schema=None)

Index("timestamp_idx", annotation.c.timestamp)
Index("device_idx", annotation.c.device)
Index("server_idx", annotation.c.server)
Index("user_idx", annotation.c.user)

autostack = Table("autostack",
                  metadata,
                  Column("uid",
                         VARCHAR(length=40),
                         primary_key=True,
                         nullable=False),
                  Column("name", VARCHAR(length=255), nullable=False),
                  Column("region", VARCHAR(length=14), nullable=False),
                  Column("filters", BLOB()),
                  schema=None)

Index("name_region", autostack.c.name, autostack.c.region, unique=True)

metric_set = Table(  # pylint: disable=C0103
    "metric_set",
    metadata,
    Column("metric",
           VARCHAR(length=40),
           ForeignKey(metric.c.uid,
                      name="metric_set_to_metric_fk",
                      onupdate="CASCADE",
                      ondelete="CASCADE"),
           nullable=False),
    Column("autostack",
Пример #17
0
# Copyright 2020 QuantStack
# Distributed under the terms of the Modified BSD License.

from sqlalchemy import (Column, ForeignKey, String, BLOB, Index, Boolean,
                        Integer, DateTime, func, UniqueConstraint)
from sqlalchemy.orm import relationship

from .database import Base

UUID = BLOB(length=16)


class User(Base):
    __tablename__ = 'users'

    id = Column(UUID, primary_key=True, index=True)
    username = Column(String, unique=True, index=True)

    identities = relationship('Identity', back_populates='user')
    profile = relationship('Profile', uselist=False, back_populates='user')


class Identity(Base):
    __tablename__ = 'identities'

    provider = Column(String, primary_key=True)
    identity_id = Column(String, primary_key=True)
    username = Column(String)
    user_id = Column(UUID, ForeignKey('users.id'))

    user = relationship('User', back_populates='identities')
Пример #18
0
class Meta(Base):
    id = Column(Integer, primary_key=True)
    entry_id = Column(Integer, ForeignKey('entry.id'))
    plugin = Column(String(PLUGIN_NAME_LENGTH),
                    index=True,
                    doc="plugin handling matadata")
    type = Column(MetaType.sql_type(), index=True)
    name = Column(String(255), index=True, doc="name of value key")
    _value = Column(BLOB())

    __tablename__ = 'meta'

    __table_args__ = (UniqueConstraint(entry_id,
                                       name,
                                       plugin,
                                       name='uix_meta_unique_name'), )

    def _get_value(self):
        if self.type == MetaType.integer:
            return int(self._value)
        elif self.type == MetaType.string:
            return str(self._value, "utf-8")
        elif self.type == MetaType.json:
            return json.loads(str(self._value, "utf-8"))
        elif self.type == MetaType.number:
            return float(str(self._value, "utf-8"))
        elif self.type == MetaType.blob:
            return self._value
        elif self.type in (MetaType.none, None):
            return None
        else:
            raise exc.DatabaseError("can't decode meta type: %s" % self.type)

    def _set_value(self, value):
        if isinstance(value, str):
            self._value = bytes(value, "utf-8")
            self.type = MetaType.string
        elif isinstance(value, int):
            self._value = bytes(str(value), "utf-8")
            self.type = MetaType.integer
        elif isinstance(value, float):
            self._value = bytes(str(value), "utf-8")
            self.type = MetaType.number
        elif isinstance(value, dict):
            self._value = bytes(json.dumps(value), "utf-8")
            self.type = MetaType.json
        elif value is None:
            self._value = bytes()
            self.type = MetaType.none
        else:
            self._value = bytes(value)
            self.type = MetaType.blob

    def _del_value(self):
        self._value = ""
        self.type = MetaType.none

    value = property(_get_value, _set_value, _del_value)

    def __repr__(self):
        return "<Meta entry='%s' name='%s' type='%s' plugin='%s'>" % (
            self.entry_id, self.name, self.type, self.plugin)
Пример #19
0
class Key(Base):
    __tablename__ = 'keys'
    fingerprint = Column(String(120), primary_key=True)
    key = Column(BLOB())
    invitation_id = Column(Integer, ForeignKey('invitations.id'))
    invitation = relationship("Invitation", back_populates='key')
Пример #20
0

autostack = Table("autostack",
                  metadata,
                  Column("uid",
                         VARCHAR(length=40),
                         primary_key=True,
                         nullable=False),
                  Column("name",
                         VARCHAR(length=255),
                         nullable=False),
                  Column("region",
                         VARCHAR(length=14),
                         nullable=False),
                  Column("filters",
                         BLOB()),
                  schema=None)

Index("name_region", autostack.c.name, autostack.c.region, unique=True)




metric_set = Table(  # pylint: disable=C0103
                   "metric_set",
                   metadata,
                   Column("metric",
                          VARCHAR(length=40),
                          ForeignKey(metric.c.uid,
                                     name="metric_set_to_metric_fk",
                                     onupdate="CASCADE", ondelete="CASCADE"),