"""add creator column
class ApicIntraPtgDB(model_base.BASEV2): __tablename__ = 'gp_apic_intra_ptg' policy_target_group_id = sa.Column( sa.String(36), sa.ForeignKey('gp_policy_target_groups.id', ondelete='CASCADE'), primary_key=True) intra_ptg_allow = sa.Column(sa.Boolean, default=True, nullable=False)
data_session = sa.Table('data_session', BaseModel.metadata, sa.Column('id', sa.Integer(), primary_key=True, autoincrement=False), sa.Column('start_at_block', sa.Integer()), sa.Column('era', sa.Integer()), sa.Column('era_idx', sa.Integer()), sa.Column('created_at_block', sa.Integer(), nullable=False), sa.Column('created_at_extrinsic', sa.Integer()), sa.Column('created_at_event', sa.Integer()), sa.Column('count_validators', sa.Integer()), sa.Column('count_nominators', sa.Integer()) ) data_session_total = sa.Table('data_session_total', BaseModel.metadata, sa.Column('id', sa.Integer(), sa.ForeignKey('data_session.id'), primary_key=True, autoincrement=False), sa.Column('end_at_block', sa.Integer()), sa.Column('count_blocks', sa.Integer()) ) class Session(BaseModel): __table__ = sa.outerjoin(data_session, data_session_total) id = column_property( data_session.c.id, data_session_total.c.id ) start_at_block = data_session.c.start_at_block era = data_session.c.era
def upgrade(): op.add_column( 'itemimages', sa.Column('parent_id', sa.Integer, sa.ForeignKey('itemimages.id')))
import sqlalchemy from db import metadata player = sqlalchemy.Table( "player", metadata, sqlalchemy.Column("id", sqlalchemy.Integer, primary_key=True), sqlalchemy.Column("name", sqlalchemy.String), sqlalchemy.Column("nationality", sqlalchemy.String), sqlalchemy.Column("kit_no", sqlalchemy.String), sqlalchemy.Column("dominant_foot", sqlalchemy.String), sqlalchemy.Column("fantasy_price", sqlalchemy.Float), sqlalchemy.Column("team_id", sqlalchemy.ForeignKey("team.id")), )
from .basic_batcher import Batcher from .db import metadata from . import patients logger = logging.getLogger(__name__) encounters_table = sa.Table( 'encounters', metadata, sa.Column('id', postgresql.INTEGER, primary_key=True), sa.Column('source_id', postgresql.TEXT, nullable=False), sa.Column( 'patient_id', postgresql.INTEGER, sa.ForeignKey('patients.id'), nullable=False, ), sa.Column('start_date', postgresql.TIMESTAMP(timezone=True), nullable=False), sa.Column('end_date', postgresql.TIMESTAMP(timezone=True), nullable=False), sa.Column('type_code', postgresql.TEXT), sa.Column('type_code_system', postgresql.TEXT), ) async def get_encounter_id(conn: Connection, source_id: str) -> str: query = (encounters_table.select().where( encounters_table.c.source_id == source_id).with_only_columns( [encounters_table.c.id]))
import logging import json from pyramid.security import Allow import sqlalchemy as sa from datetime import datetime from ringo.lib.alchemy import get_prop_from_instance from ringo.model import Base from ringo.model.base import BaseItem, BaseFactory from ringo.model.mixins import Owned log = logging.getLogger(__name__) password_reset_requests = sa.Table( 'password_reset_requests', Base.metadata, sa.Column('id', sa.Integer, primary_key=True), sa.Column('uid', sa.Integer, sa.ForeignKey('users.id')), sa.Column('created', sa.DateTime), sa.Column('token', sa.String)) # NM-Table definitions nm_user_roles = sa.Table( 'nm_user_roles', Base.metadata, sa.Column('uid', sa.Integer, sa.ForeignKey('users.id')), sa.Column('rid', sa.Integer, sa.ForeignKey('roles.id')), sa.UniqueConstraint('uid', 'rid')) nm_user_usergroups = sa.Table( 'nm_user_usergroups', Base.metadata, sa.Column('uid', sa.Integer, sa.ForeignKey('users.id')), sa.Column('gid', sa.Integer, sa.ForeignKey('usergroups.id')), sa.UniqueConstraint('uid', 'gid'))
def changed_by_fk(self): # noqa return sa.Column(sa.Integer, sa.ForeignKey('ab_user.id'), default=self.get_user_id, onupdate=self.get_user_id, nullable=True)
def upgrade(migrate_engine): metadata = sa.MetaData() metadata.bind = migrate_engine sa.Table( 'sourcestamps', metadata, sa.Column('id', sa.Integer, primary_key=True), sa.Column('ss_hash', sa.String(40), nullable=False), sa.Column('branch', sa.String(256)), sa.Column('revision', sa.String(256)), sa.Column('patchid', sa.Integer, sa.ForeignKey('patches.id')), sa.Column('repository', sa.String(length=512), nullable=False, server_default=''), sa.Column('codebase', sa.String(256), nullable=False, server_default=sa.DefaultClause("")), sa.Column('project', sa.String(length=512), nullable=False, server_default=''), sa.Column('created_at', sa.Integer, nullable=False)) # Specify what the new table should look like changes = sa.Table( 'changes', metadata, sa.Column('changeid', sa.Integer, primary_key=True), sa.Column('author', sa.String(256), nullable=False), sa.Column('comments', sa.String(1024), nullable=False), sa.Column('branch', sa.String(256)), sa.Column('revision', sa.String(256)), sa.Column('revlink', sa.String(256)), sa.Column('when_timestamp', sa.Integer, nullable=False), sa.Column('category', sa.String(256)), sa.Column('repository', sa.String(length=512), nullable=False, server_default=''), sa.Column('codebase', sa.String(256), nullable=False, server_default=sa.DefaultClause("")), sa.Column('project', sa.String(length=512), nullable=False, server_default=''), sa.Column('sourcestampid', sa.Integer, sa.ForeignKey('sourcestamps.id'))) # Now drop column changeset.drop_column(sa.Column('is_dir', sa.SmallInteger, nullable=False), table=changes, metadata=metadata, engine=migrate_engine) # re-create all indexes on the table - sqlite dropped them if migrate_engine.dialect.name == 'sqlite': idx = sa.Index('changes_branch', changes.c.branch) idx.create() idx = sa.Index('changes_revision', changes.c.revision) idx.create() idx = sa.Index('changes_author', changes.c.author) idx.create() idx = sa.Index('changes_category', changes.c.category) idx.create() idx = sa.Index('changes_when_timestamp', changes.c.when_timestamp) idx.create() idx = sa.Index('changes_sourcestampid', changes.c.sourcestampid) idx.create()
class Demo2(db.Model): __tablename__ = "demo2" pk = sa.Column(sa.Integer, primary_key=True) fk = sa.Column(sa.Integer, sa.ForeignKey(Demo.pk))
import sqlalchemy from .db_session import SqlAlchemyBase association_table = sqlalchemy.Table('association', SqlAlchemyBase.metadata, sqlalchemy.Column('news', sqlalchemy.Integer, sqlalchemy.ForeignKey('news.id')), sqlalchemy.Column('tasks', sqlalchemy.Integer, sqlalchemy.ForeignKey('tasks.id')), sqlalchemy.Column('category', sqlalchemy.Integer, sqlalchemy.ForeignKey('category.id')) ) class Category(SqlAlchemyBase): __tablename__ = 'category' id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, autoincrement=True) name = sqlalchemy.Column(sqlalchemy.String, nullable=True)
class AlertChannelAction(Base, BaseModel): """ Stores notifications conditions for user's alert channels This is later used for rule parsing like "alert if http_status == 500" """ __tablename__ = "alert_channels_actions" types = ["report", "chart"] owner_id = sa.Column( sa.Integer, sa.ForeignKey("users.id", onupdate="CASCADE", ondelete="CASCADE")) resource_id = sa.Column(sa.Integer()) action = sa.Column(sa.Unicode(10), nullable=False, default="always") type = sa.Column(sa.Unicode(10), nullable=False) other_id = sa.Column(sa.Unicode(40)) pkey = sa.Column(sa.Integer(), nullable=False, primary_key=True) rule = sa.Column( sa.dialects.postgresql.JSON, nullable=False, default={ "field": "http_status", "op": "ge", "value": "500" }, ) config = sa.Column(sa.dialects.postgresql.JSON) name = sa.Column(sa.Unicode(255)) @validates("notify_type") def validate_email(self, key, notify_type): assert notify_type in ["always", "only_first"] return notify_type def resource_name(self, db_session=None): db_session = get_db_session(db_session) if self.resource_id: return ResourceService.by_resource_id( self.resource_id, db_session=db_session).resource_name else: return "any resource" def get_dict(self, exclude_keys=None, include_keys=None, extended_info=False): """ Returns dictionary with required information that will be consumed by angular """ instance_dict = super(AlertChannelAction, self).get_dict() exclude_keys_list = exclude_keys or [] include_keys_list = include_keys or [] if extended_info: instance_dict["channels"] = [ c.get_dict(extended_info=False) for c in self.channels ] d = {} for k in instance_dict.keys(): if k not in exclude_keys_list and (k in include_keys_list or not include_keys): d[k] = instance_dict[k] return d
class BlogPost(TextItem): __tablename__ = 'blog_post' id = sa.Column(sa.Integer, sa.ForeignKey(TextItem.id), primary_key=True) __mapper_args__ = {'polymorphic_identity': u'blog_post'}
class SubnetRoute(model_base.BASEV2, Route): subnet_id = sa.Column(sa.String(36), sa.ForeignKey('subnets.id', ondelete="CASCADE"), primary_key=True)
engine = sqlalchemy.create_engine('sqlite:///') metadata = MetaData(bind=engine) unicode_table = sqlalchemy.Table( 'cjk', metadata, sqlalchemy.Column('id', sqlalchemy.Integer(), primary_key=True), sqlalchemy.Column('char', sqlalchemy.Unicode()), sqlalchemy.Column('ucn', sqlalchemy.String()), ) sample_table = sqlalchemy.Table( 'sample_table', metadata, sqlalchemy.Column('id', sqlalchemy.Integer(), primary_key=True), sqlalchemy.Column('char_id', sqlalchemy.ForeignKey('cjk.id')), sqlalchemy.Column('value', sqlalchemy.Unicode()), ) metadata.create_all() def get_char_fk(char): return (unicode_table.select(unicode_table.c.id).where( unicode_table.c.char == char).limit(1).execute().fetchone().id) def get_char_fk_multiple(*args): """Retrieve the Rows""" where_opts = []
import sqlalchemy as db from sqlalchemy import create_engine, MetaData from sqlalchemy.orm import sessionmaker, relationship, backref from sqlalchemy.ext.declarative import declarative_base import requests from bs4 import BeautifulSoup import datetime ### Настройки Базы Данных Тани### conn = db.create_engine('sqlite:////home/janna/Python/For_git/Tanya/Tanya.db') Session = sessionmaker() session = Session(bind=conn) Base = declarative_base() metadata = MetaData() association = db.Table( 'association', Base.metadata, db.Column('post_id', db.Integer, db.ForeignKey('posts.post_id')), db.Column('tag_id', db.Integer, db.ForeignKey('tags.tag_id')), )