class Account(Base): __tablename__ = 'account' id = Column(BINARY(16), primary_key=True) username = Column(VARCHAR(64), primary_key=True) alias = Column(VARCHAR(64), unique=True) password = Column(BINARY(64)) salt = Column(BINARY(16))
class Base36UID(TypeDecorator): impl = BINARY(16) # 128 bit unsigned integer def process_bind_param(self, value, dialect): if not value: return None return b36_to_bin(value) def process_result_value(self, value, dialect): return int128_to_b36(value)
class Base36UID(TypeDecorator): cache_ok = True impl = BINARY(16) # 128 bit unsigned integer def process_bind_param(self, value, dialect): # type: (Optional[str], Any) -> Optional[bytes] if not value: return None return b36_to_bin(value) def process_result_value(self, value, dialect): # type: (Optional[bytes], Any) -> Optional[str] return int128_to_b36(value)
class Record(_Model): __tablename__ = 'record' __table_args__ = { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8', 'mysql_row_format': 'compressed', 'mysql_key_block_size': '4', } id = Column(BINARY(24), primary_key=True) date = Column(Date, nullable=False) type = Column(String(256), nullable=False) source_id = Column(String(256), nullable=False) value = Column(LargeBinary)
class IOCType(UserDefinedType): impl = BINARY(16) def bind_processor(self, dialect): DBAPIBinary = dialect.dbapi.Binary def process(value): if type(value) == str: value = value.encode('utf-8') return DBAPIBinary(value) return process def result_processor(self, dialect, coltype): def process(value): return value return process @property def python_type(self): return self.impl.type.python_type
class Entity(Base): __tablename__ = 'entity' id = Column(BINARY(16), primary_key=True) account_id = Column(ForeignKey('account.id', ondelete='CASCADE'), nullable=True) name = Column(VARCHAR(64), unique=True)
from sqlalchemy.schema import (Column, ForeignKey, Index, MetaData, Table, UniqueConstraint) from sqlalchemy.types import BINARY, BLOB, INTEGER, JSON, TEXT, VARCHAR from lib import logger, mysql_engine # Constants CHAR_MAX_LEN = 255 BINARY_MAX_LEN = 2**32 - 1 SHA1_LEN = 20 # Types LONGBLOB = BLOB(length=BINARY_MAX_LEN) LONGTEXT = TEXT(length=BINARY_MAX_LEN) LONGVARCHAR = VARCHAR(length=CHAR_MAX_LEN) SHA1 = BINARY(length=SHA1_LEN) # Table metadata metadata = MetaData(bind=mysql_engine) # All known strace executables and arguments executables = Table( 'executables', metadata, Column('id', INTEGER, primary_key=True), Column('system', LONGVARCHAR, nullable=False), Column('executable', LONGVARCHAR, nullable=False), Column('arguments_hash', SHA1, nullable=False), Column('arguments', JSON, nullable=False), Index('system', 'executable', 'arguments_hash'), )
from sqlalchemy import (MetaData, Table, Column, Integer, String, Text, ForeignKey, PrimaryKeyConstraint) from sqlalchemy.types import BINARY, Enum from sqlalchemy.dialects.mysql import LONGBLOB from migrate import * from anakin.preprocess.dataset import Dataset meta = MetaData() file_table = Table('files', meta, Column('id', Integer, primary_key=True), Column('dataset', Enum(Dataset)), Column('file_name', String(100), unique=True), Column('contents', LONGBLOB), Column('checksum', BINARY(20), unique=True)) data_table = Table( 'datum', meta, Column('id', Integer), Column('contents', Text), Column( 'file_id', Integer, ForeignKey('files.id', onupdate='CASCADE', ondelete='CASCADE'), ), PrimaryKeyConstraint('id', 'file_id')) sentence_table = Table( 'sentences', meta, Column('id', Integer, primary_key=True), Column('contents', Text), Column('data_id', Integer), Column('data_file_id', Integer), ForeignKeyConstraint(['data_id', 'data_file_id'], ['datum.id', 'datum.file_id']))
def load_dialect_impl(self, dialect): """Get corresponding TypeEngine object""" if dialect.name == 'postgresql': return dialect.type_descriptor(postgresql.UUID(as_uuid=True)) return dialect.type_descriptor(BINARY(16))
def load_dialect_impl(self, dialect): if dialect.name == 'postgresql': return dialect.type_descriptor(UUID()) else: return dialect.type_descriptor(BINARY(32))
class Image(Base): __tablename__ = 'image' id = Column(BINARY(16), primary_key=True) entity_id = Column(ForeignKey('entity.id')) blob = Column(BLOB(255))
def load_dialect_impl(self, dialect): if dialect.name == "postgresql": return dialect.type_descriptor(psqlUUID()) else: return dialect.type_descriptor(BINARY(16))