def _resolve_mapped_attribute_names(self, mapper: Mapper, mapped_class: Type[Any]) -> None: """Looks up attribute name on the mapped class for each tracked column. This column->attribute name mapping is created separately for each mapped class. This allows multiple mapped classes against the same table to have different attribute names to refer to a column. """ for column in self._columns: if column in mapper.columns.values(): attr = mapper.get_property_by_column(column) if len(self._columns) == 1: self._singles[mapped_class] = attr.key self._targets[mapped_class][column] = attr.key
#!/usr/bin/env python # -*- coding:utf-8 -*- from . import metadata from sqlalchemy import Column, String, Text, Integer, Table from sqlalchemy.orm import Mapper MachineTB = Table( 'fb_machine', metadata, Column('id', String(40), primary_key=True), Column('name', String, nullable=False), Column('account', String, nullable=True), Column('password', String, nullable=True), Column('desc', Text, nullable=True), Column('create_time', Integer), Column('ip', String, nullable=False), Column('auth_type', String, nullable=False, default='password'), Column('is_valid', String, nullable=False, default='yes'), ) class MachineMapping(object): pass Mapper(MachineMapping, MachineTB)
def temporal_map(*track, mapper: orm.Mapper, activity_class=None, schema=None, allow_persist_on_commit=False): """ maps properties to temporal models, builds a clock table, handles optional activity class for changes """ assert 'vclock' not in track cls = mapper.class_ entity_table = mapper.local_table # get things defined on Temporal: tracked_props = frozenset( mapper.get_property(prop) for prop in track ) # make sure all temporal properties have active_history (always loaded) for prop in tracked_props: getattr(cls, prop.key).impl.active_history = True schema = schema or entity_table.schema clock_table = build_clock_table( entity_table, entity_table.metadata, schema, activity_class, ) clock_properties = { 'entity': orm.relationship( lambda: cls, backref=orm.backref('clock', lazy='dynamic'), ), 'entity_first_tick': orm.relationship( lambda: cls, backref=orm.backref( 'first_tick', primaryjoin=sa.and_( clock_table.join(entity_table).onclause, clock_table.c.tick == 1, ), innerjoin=True, uselist=False, # single record viewonly=True, # view only ), ), 'entity_latest_tick': orm.relationship( lambda: cls, backref=orm.backref( 'latest_tick', primaryjoin=sa.and_( clock_table.join(entity_table).onclause, entity_table.c.vclock == clock_table.c.tick, ), innerjoin=True, uselist=False, # single record viewonly=True, # view only ), ), '__table__': clock_table, } # used to construct a new clock model for this entity if activity_class: # create a relationship to the activity from the clock model backref_name = '%s_clock' % entity_table.name clock_properties['activity'] = \ orm.relationship(lambda: activity_class, backref=backref_name) clock_model = build_clock_class(cls.__name__, entity_table.metadata, clock_properties) history_models = { p: build_history_class(cls, p, schema) for p in tracked_props } cls.temporal_options = TemporalOption( temporal_props=tracked_props, history_models=history_models, clock_model=clock_model, activity_cls=activity_class, allow_persist_on_commit=allow_persist_on_commit, ) event.listen(cls, 'init', init_clock)
__date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_rank = Table( "rank", metadata, Column("type", Integer, primary_key=True), Column("rank", Integer, primary_key=True), Column("period_type", Integer, primary_key=True), Column("period", Integer, primary_key=True), Column("uid", Integer), Column("rank_value", Integer, default=-1), ) class TRank(TableObject): def __init__(self): TableObject.__init__(self) mapper_rank = Mapper(TRank, tab_rank) if __name__ == "__main__": pass
from sqlalchemy import create_engine from sqlalchemy import MetaData, Table, Column, Integer, String from sqlalchemy.orm import Mapper Engine = create_engine('sqlite:///classical_map.sqlite') meta_data = MetaData() Administer = Table('Administer', meta_data, Column('id', Integer, primary_key=True), Column('Name', String(20)), Column('password', String(30)) ) class Admin(): def __init__(self, Name, password): self.Name= Name self.password= password Mapper(Admin,Administer) meta_data.create_all(Engine)
tab_flow_items = Table( "flow_items", metadata, Column("id", Integer, primary_key=True), Column("icon", Integer), Column("name", String(255)), Column("sn", Integer), Column("sn_name", String(255)), Column("GSM", String(20)), Column("description", String(140)), Column("card", Integer), Column("stack", Integer), Column("used", Integer), Column("create_time", DateTime), Column("sort", Integer), ) class TFlowItems(TableObject): def __init__(self): TableObject.__init__(self) def __repr__(self): return 'id=%d,name=%s' % (self.id, self.name) mapper_flow_items = Mapper(TFlowItems, tab_flow_items) if __name__ == "__main__": pass
# -*- coding: utf-8 -*- __author__ = 'Administrator' from db.connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_order_params = Table( "order_params", metadata, Column("order_id", Integer, primary_key=True), Column("params", String(255)), ) class TOrderParams(TableObject): def __init__(self): TableObject.__init__(self) # def __repr__(self): # return "id=%id,icon=%s,name=%s,description=%s,gold=%d" % \ # (self.id,self.icon,self.name,self.description,self.gold) mapper_order_params = Mapper(TOrderParams, tab_order_params) if __name__ == "__main__": pass
__copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table,Column,func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_gift = Table("gift", metadata, Column("id",Integer, primary_key=True), Column("icon",String(100)), Column("name",String(20)), Column("description",String(140)), Column("gold",BigInteger), Column("create_time", DateTime), ) class TGift(TableObject): def __init__(self): TableObject.__init__(self) # def __repr__(self): # return "id=%id,icon=%s,name=%s,description=%s,gold=%d" % \ # (self.id,self.icon,self.name,self.description,self.gold) mapper_gift = Mapper(TGift,tab_gift) if __name__=="__main__": pass
#!/usr/bin/env python # -*- coding:utf-8 -*- from . import metadata from sqlalchemy import Column, Integer, String, Table from sqlalchemy.orm import Mapper FabricRelationTB = Table( 'fb_fabric_relation', metadata, Column('id', String(40), primary_key=True), Column('fabric_id', String, nullable=False), Column('project_id', String, nullable=False), Column('machine_id', String, nullable=False), Column('status', String, nullable=False, default='not_deploy'), Column('error', String, nullable=True), Column('create_time', Integer, nullable=False), Column('fabric_time', Integer, nullable=True), Column('finish_time', Integer, nullable=True), ) class FabricRelationMapping(object): pass Mapper(FabricRelationMapping, FabricRelationTB)
from db.connect import * from sqlalchemy import Table,Column,func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_pop_activity = Table("pop_activity", metadata, Column("id",Integer, primary_key=True), Column("title",String(50)), Column("description",String(255)), Column("gold",Integer), Column("money",DECIMAL(10,2)), Column("start", DateTime), Column("end", DateTime), Column("status",Integer), ) class TPopActivity(TableObject): def __init__(self): TableObject.__init__(self) # def __repr__(self): # return "id=%id,icon=%s,name=%s,description=%s,gold=%d" % \ # (self.id,self.icon,self.name,self.description,self.gold) mapper_pop_activity = Mapper(TPopActivity,tab_pop_activity) if __name__=="__main__": pass
from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_friend_apply = Table( "friend_apply", metadata, Column("id", Integer, primary_key=True), Column("apply_uid", Integer, nullable=False), # 申请方 Column("to_uid", Integer, nullable=False), # 答复方 Column("gifts", String(100)), # 格式如下:"(gift_id,count),(gift_id,count),...." Column("message", String(140)), Column("state", SmallInteger, nullable=False), Column("apply_time", DateTime, nullable=False), Column("finish_time", DateTime), ) class TFriendApply(TableObject): def __init__(self): TableObject.__init__(self) def __repr__(self): return 'id=%d,apply_uid=%d,to_uid=%d,gifts=%s,message=%s,state=%d,apply_time=%s,finish_time=%s' % \ (self.id,self.apply_uid,self.to_uid,self.gifts,self.message,self.state,str(self.apply_time),str(self.finish_time)) mapper_friend_apply = Mapper(TFriendApply, tab_friend_apply) if __name__ == "__main__": pass
__version__ = "1.0" __date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table,Column,func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_goldflower = Table("goldflower", metadata, Column("id",Integer, primary_key=True), Column("type",Integer), Column("countof_gamblers",SmallInteger), # 玩家数量 Column("winner",Integer,default=-1), Column("gold",BigInteger,default=0), Column("fee",BigInteger,default=0), Column("create_time", DateTime), ) class TGoldFlower(TableObject): def __init__(self): TableObject.__init__(self) mapper_goldflower = Mapper(TGoldFlower,tab_goldflower) if __name__=="__main__": pass
__date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_broke_gold_log = Table( "broke_gold_log", metadata, Column("id", Integer, primary_key=True), Column("uid", Integer, primary_key=True), Column("gold", Integer, nullable=False), Column("total", Integer, nullable=False), Column("current", Integer, nullable=False), Column("create_time", DateTime), ) class TBrokeGoldLog(TableObject): def __init__(self): TableObject.__init__(self) mapper_broke_gold_log = Mapper(TBrokeGoldLog, tab_broke_gold_log) if __name__ == "__main__": pass
from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_trade = Table( "trade", metadata, Column("id", Integer, primary_key=True), Column("seller", Integer), Column("gold", BigInteger), Column("fee", Integer), Column("diamond", BigInteger), Column("sell_time", DateTime), Column("buyer", Integer), Column("buy_time", DateTime), Column("status", SMALLINT), Column("rate", DECIMAL(11, 2)), ) class TTrade(TableObject): def __init__(self): TableObject.__init__(self) def __repr__(self): return 'id=%d' % self.id mapper_trade = Mapper(TTrade, tab_trade) if __name__ == "__main__": pass
#!/usr/bin/env python # -*- coding:utf-8 -*- from . import metadata from sqlalchemy import Column, Integer, String, Table from sqlalchemy.orm import Mapper UserTB = Table('fb_user', metadata, Column('id', String(40), primary_key=True), Column('loginname', String(40), nullable=False), Column('nickname', String, nullable=False), Column('password', String, nullable=False), Column('avatar', String, nullable=True), Column('create_time', Integer)) class UserMapping(object): pass Mapper(UserMapping, UserTB)
__version__ = "1.0" __date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_activity_wheel_log = Table( "activity_wheel_log", metadata, Column("id", Integer, primary_key=True), Column("round", Integer), Column("uid", Integer), Column("reward_item", String(255)), Column("create_time", DateTime), ) class TActivityWheelLog(TableObject): def __init__(self): TableObject.__init__(self) mapper_activity_wheel_log = Mapper(TActivityWheelLog, tab_activity_wheel_log) if __name__ == "__main__": pass
# -*- coding:utf-8 -*- from . import metadata from sqlalchemy import Column, Integer, String, Table from sqlalchemy.orm import Mapper FabricTB = Table( 'fb_fabric', metadata, Column('id', String(40), primary_key=True), Column('tag', String, nullable=False), Column('project_id', String, nullable=False), Column('desc', String, nullable=True), Column('status', String, nullable=False, default='edit'), Column('type', String, nullable=False), Column('create_time', Integer, nullable=False), Column('fabric_time', Integer, nullable=True), Column('finish_time', Integer, nullable=True), Column('total', Integer, nullable=True, default=0), Column('success_num', Integer, nullable=True, default=0), Column('error_num', Integer, nullable=True, default=0), Column('error', String, nullable=True), ) class FabricMapping(object): pass Mapper(FabricMapping, FabricTB)
def mapping_exists_table(self, p_class, p_table): logging.info("Отображаем таблицу {0} на класс".format(p_table)) Mapper(p_class, self._metadata.tables[p_table]) return p_class
__version__ = "1.0" __date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_bank_account = Table( "bank_account", metadata, Column("uid", Integer, primary_key=True), Column("gold", Integer, default=0, nullable=False), Column("diamond", Integer, default=0, nullable=False), Column("update_time", DateTime, nullable=False), Column("create_time", DateTime, nullable=False), ) class TBankAccount(TableObject): def __init__(self): TableObject.__init__(self) mapper_bank_account = Mapper(TBankAccount, tab_bank_account) if __name__ == "__main__": pass
__version__ = "1.0" __date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_item = Table( "item", metadata, Column("id", Integer, primary_key=True), Column("icon", String(100)), Column("name", String(20)), Column("description", String(140)), Column("create_time", DateTime), ) class TItem(TableObject): def __init__(self): TableObject.__init__(self) mapper_item = Mapper(TItem, tab_item) if __name__ == "__main__": pass
__version__ = "1.0" __date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_activity_user = Table( "activity_user", metadata, Column("uid", Integer, primary_key=True), Column("params", String(255)), ) class TActivityUser(TableObject): def __init__(self): TableObject.__init__(self) def __repr__(self): return 'uid=%d,params=%s' % (self.uid, self.params) mapper_activity_user = Mapper(TActivityUser, tab_activity_user) if __name__ == "__main__": pass
__date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_robot_texas = Table( "robot_texas", metadata, Column("uid", Integer, primary_key=True), Column("online_times", String(255)), Column("type", SmallInteger), Column("win_gold", BigInteger), Column("state", SmallInteger, default=1), Column("create_time", DateTime), ) class TRobotTexas(TableObject): def __init__(self): TableObject.__init__(self) mapper_robot_texas = Mapper(TRobotTexas, tab_robot_texas) if __name__ == "__main__": pass
""" __author__ = "*****@*****.**" __version__ = "1.0" __date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper #������ tab_timer = Table("timer", metadata, Column("id", Integer, primary_key=True), Column("uid", Integer), Column("object_id", BigInteger), Column("object_type", SmallInteger), Column("event_id", Integer), Column("expired", Integer), Column("param0", BigInteger), Column("param1", BigInteger)) class TTimer(TableObject): def __init__(self): TableObject.__init__(self) mapper_timer = Mapper(TTimer, tab_timer) if __name__ == "__main__": pass
from db.connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_robot_war = Table( "robot_war", metadata, Column("uid", Integer, primary_key=True), Column("online_times", String(255)), Column("type", SmallInteger), Column("win_gold", BigInteger), Column("state", SmallInteger, default=1), Column("create_time", DateTime), ) class TRobotWar(TableObject): def __init__(self): TableObject.__init__(self) def __repr__(self): return 'uid=%d,online_times=%s,type=%d,win_gold=%d,state=%d' % ( self.uid, self.online_times, self.type, self.win_gold, self.state) mapper_robot_war = Mapper(TRobotWar, tab_robot_war) if __name__ == "__main__": pass
tab_mail = Table("mail", metadata, Column("id",Integer, primary_key=True), Column("from_user",Integer,nullable =False), Column("to_user",Integer,nullable =False), Column("sent_time", Integer,nullable =False), Column("title", String(100)), Column("content", String(2000)), Column("type", SmallInteger,nullable =False), Column("diamond", BigInteger,default=0,nullable =False), Column("gold", BigInteger,default=0,nullable =False), Column("flow_card", BigInteger,default=0,nullable =False), Column("items", String(200)), Column("gifts", String(200)), Column("received_time", Integer), Column("state", SmallInteger,default=0,nullable =False), # 0 未收取 ) class TMail(TableObject): def __init__(self): TableObject.__init__(self) def __repr__(self): return 'id=%d,from_user=%d,to_user=%d,sent_time=%d,title=%s,content=%s,type=%d,diamond=%d,gold=%d,state=%d' % \ (self.id,self.from_user,self.to_user,self.sent_time,self.title,self.content,self.type,self.diamond,self.gold,self.state) mapper_mail = Mapper(TMail,tab_mail) if __name__=="__main__": pass
__author__ = "*****@*****.**" __version__ = "1.0" __date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_bag_gift = Table( "bag_gift", metadata, Column("uid", Integer, primary_key=True), Column("gift_id", Integer, primary_key=True), Column("countof", Integer, nullable=False), ) class TBagGift(TableObject): def __init__(self): TableObject.__init__(self) mapper_bag_gift = Mapper(TBagGift, tab_bag_gift) if __name__ == "__main__": pass
__author__ = "*****@*****.**" __version__ = "1.0" __date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table,Column,func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_lucky = Table("lucky", metadata, Column("uid",Integer, primary_key=True), Column("lucky",Integer,nullable =False), Column("games",Integer,nullable =False), Column("config_id", Integer,nullable =False), ) class TLucky(TableObject): def __init__(self): TableObject.__init__(self) mapper_lucky = Mapper(TLucky,tab_lucky) if __name__=="__main__": pass
__copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table, Column, func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_bag_item = Table( "bag_item", metadata, Column("uid", Integer, primary_key=True), Column("item_id", Integer, primary_key=True), Column("countof", Integer, nullable=False), ) class TBagItem(TableObject): def __init__(self): TableObject.__init__(self) def __repr__(self): return 'uid=%d,item_id=%d,countof=%d' % (self.uid, self.item_id, self.countof) mapper_bag_item = Mapper(TBagItem, tab_bag_item) if __name__ == "__main__": pass
__author__ = "*****@*****.**" __version__ = "1.0" __date__ = "2011/04/14" __copyright__ = "Copyright (c) 2011" __license__ = "Python" from db.connect import * from sqlalchemy import Table,Column,func from sqlalchemy.types import * from sqlalchemy.orm import Mapper tab_robot = Table("robot", metadata, Column("uid",Integer, primary_key=True), Column("online_times",String(255)), Column("type",SmallInteger), Column("win_gold",BigInteger), Column("state",SmallInteger,default=1), Column("create_time", DateTime), ) class TRobot(TableObject): def __init__(self): TableObject.__init__(self) mapper_robot = Mapper(TRobot,tab_robot) if __name__=="__main__": pass
metadata, Column("id", Integer, primary_key=True), Column("diamond", Integer, default=0, nullable=False), Column("type", String(10)), Column("gold", Integer), Column("icon", String(20)), Column("name", String(20)), Column("money", DECIMAL(18, 2)), Column("real_money", DECIMAL(18, 2)), Column("description", String(140), nullable=False), Column("extra_diamond", Integer, default=0), Column("extra_items", String(100), default=""), # 赠送道具列表,格式如下:"item_id-count,item_id-count....." Column("create_time", DateTime, nullable=False), ) class TChargeItem(TableObject): def __init__(self): TableObject.__init__(self) def __repr__(self): return 'id=%d,diamond=%d,descript=%s,money=%s,real_money=%s' % ( self.id, self.diamond, self.description, self.money, self.real_money) mapper_charge_item = Mapper(TChargeItem, tab_charge_item) if __name__ == "__main__": pass