Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'attributes': 0.07; 'class,': 0.07; 'components.': 0.09; 'holdings': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'aug': 0.13; '(the': 0.15; 'component': 0.15; 'sat,': 0.15; '"list': 0.16; 'boolean': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sqlalchemy': 0.16; 'sqlalchemy,': 0.16; 'them...': 0.16; 'instance': 0.17; 'integer': 0.17; 'refers': 0.17; 'holds': 0.20; 'question.': 0.20; 'all:': 0.22; 'setup,': 0.22; 'player': 0.23; 'supported': 0.26; 'object,': 0.27; 'header:X-Complaints-To:1': 0.28; 'key,': 0.29; 'table,': 0.29; 'objects': 0.29; 'primary': 0.30; 'could': 0.32; 'comments': 0.33; 'subject:data': 0.33; 'url:home': 0.33; 'to:addr :python-list': 0.33; 'everyone': 0.33; 'another': 0.33; 'text': 0.34; 'list': 0.35; 'whatever': 0.35; 'table': 0.35; 'something': 0.35; 'add': 0.36; 'received:org': 0.36; 'living': 0.36; 'subject:with': 0.36; 'charset:us-ascii': 0.36; 'being': 0.37; 'item': 0.37; 'ones': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'description': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'contents.': 0.65; 'foreign': 0.72; 'bag': 0.75; 'enumeration': 0.84; 'game,': 0.84; 'subject:modeling': 0.84; 'treasure': 0.84; 'dennis': 0.91; 'cutting': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: modeling complex data with sqlalchemy Date: Sat, 25 Aug 2012 19:53:07 -0400 Organization: > Bestiaria Support Staff < References: <503939E7.8080506@tysdomain.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-19-241.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 81 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345938798 news.xs4all.nl 6941 [2001:888:2000:d::a6]:56046 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27891 On Sat, 25 Aug 2012 14:47:35 -0600, "Littlefield, Tyler" declaimed the following in gmane.comp.python.general: > Hello all: > I had a quick question. > In my game, I have an is-a setup, where all objects contain data like an > id for sqlalchemy, a name, a description and a list of contents. Well, a "list of contents" comes down to a table of items with a foreign key to the item "containing" them... create table objects ( ID integer auto-increment primary key, name varchar(?), description varchar(?) ) 1, Wulfraed, something or other 2, Bag of Holding, whatever 3, Sword, some cutting comments 4, Treasure Chest, everyone wants one create table holdings ( ID integer auto-increment primary key, holder integer foreign key objects(ID), holding integer foreign key objects(ID) ) 1, 1, 2 2, 1, 3 3, 2, 4 > In order to add functionality to an object, you add components. So for > example, a player would have the Player and Living component associated create table attribute_types ( ID integer auto-increment primary key, name varchar(?), type char(?), #or an enumeration if supported by the RDBM #and SQLAlchemy ) 1, Player, Boolean 2, Living, Boolean 3, EdgeWeapon, Boolean 4, Damage, DieRoll 5, ContainerSize, Integer 6, Class, Text create table attributes ( ID integer auto-increment primary key, describes integer foreign key objects(ID), attribute integer foreign key attribute_types(ID), value BLOB(?) ) 1, 1, 1, blob(True) 2, 1, 2, blob(True) 3, 3, 3, blob(True) 4, 3, 4, blob("1D8 + 4") 5, 2, 5, blob(-1) #-1 being unlimited, bag of holding 6, 4, 5, blob(6) #treasure chest holds 6 units of objects 7, 1, 6, blob("Ranger") Now, you could add another layer of indirection -- a table of pre-defined object /types/ (different types of containers, swords, other weapons), and have each instance (the ones shown in "objects") refer to the object type table, and the object type table is what the object attributes refers to. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/