Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #27934

Re: modeling complex data with sqlalchemy

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <tyler@tysdomain.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'attributes': 0.07; 'class,': 0.07; 'table.': 0.07; 'components,': 0.09; 'components.': 0.09; 'holdings': 0.09; 'inherited': 0.09; 'aug': 0.13; '(the': 0.15; 'component': 0.15; 'sat,': 0.15; '"list': 0.16; 'boolean': 0.16; 'from:addr:tyler': 0.16; 'from:addr:tysdomain.com': 0.16; 'from:name:littlefield, tyler': 0.16; 'hello:': 0.16; 'message-id:@tysdomain.com': 0.16; 'received:69.164': 0.16; 'received:69.164.206': 0.16; 'received:69.164.206.65': 0.16; 'received:tds-solutions.net': 0.16; 'sqlalchemy': 0.16; 'sqlalchemy,': 0.16; 'them...': 0.16; 'wanted.': 0.16; 'wrote:': 0.17; 'have:': 0.17; 'instance': 0.17; 'integer': 0.17; 'refers': 0.17; 'holds': 0.20; 'question.': 0.20; 'bit': 0.21; 'all:': 0.22; 'info.': 0.22; 'own.': 0.22; 'received:192.168.1.100': 0.22; 'setup,': 0.22; 'player': 0.23; 'idea': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'supported': 0.26; 'object,': 0.27; "doesn't": 0.28; 'this?': 0.28; 'actual': 0.28; 'key,': 0.29; 'project:': 0.29; 'table,': 0.29; 'objects': 0.29; 'url:code': 0.29; "i'm": 0.29; 'primary': 0.30; 'could': 0.32; 'comments': 0.33; 'subject:data': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'everyone': 0.33; 'another': 0.33; "can't": 0.34; 'text': 0.34; 'thanks': 0.34; 'list': 0.35; 'whatever': 0.35; 'pm,': 0.35; 'table': 0.35; 'something': 0.35; 'there': 0.35; 'add': 0.36; 'really': 0.36; 'but': 0.36; 'living': 0.36; 'subject:with': 0.36; 'being': 0.37; 'item': 0.37; 'ones': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'object': 0.38; 'some': 0.38; 'description': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'easy': 0.60; 'relationship': 0.60; 'url:p': 0.63; 'contents.': 0.65; 'foreign': 0.72; 'bag': 0.75; 'different.': 0.84; 'enumeration': 0.84; 'game,': 0.84; 'light-weight': 0.84; 'player.': 0.84; 'subject:modeling': 0.84; 'treasure': 0.84; 'care,': 0.91; 'dennis': 0.91; 'cutting': 0.93
X-Spam-Checker-Version SpamAssassin 3.3.1 (2010-03-16) on wuff
X-Spam-Level
X-Spam-Status No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=unavailable version=3.3.1
Date Sun, 26 Aug 2012 10:38:09 -0600
From "Littlefield, Tyler" <tyler@tysdomain.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0
MIME-Version 1.0
To python-list@python.org
Subject Re: modeling complex data with sqlalchemy
References <503939E7.8080506@tysdomain.com> <35oi38lk2am7dd9d3emrkso79uq7ugfeb0@invalid.netcom.com>
In-Reply-To <35oi38lk2am7dd9d3emrkso79uq7ugfeb0@invalid.netcom.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3844.1345999106.4697.python-list@python.org> (permalink)
Lines 100
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1345999106 news.xs4all.nl 6920 [2001:888:2000:d::a6]:35826
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:27934

Show key headers only | View raw


Hello:
Thanks for the info. IT doesn't really model the data I wanted. The 
contents was easy enough, I'm just going to set up a 1:n relationship on 
the Entity to the actual player. But for components, it's a bit different.
Each component inherits the actual Component class, and has a number of 
attributes on it. I can't just put it in it's own. So I was going to set 
up a table per component and then just store an id and another id for 
what holds it. But my problem is modeling it. I also need the inherited 
data from Component. Would there be a way to do this? I could have:
id, name, component_id
and then SA could use the name as the table's name, and the id as the id 
of the component in the other table.
How would I set this up with SA? Is it a good idea to go this route?

On 8/25/2012 5:53 PM, Dennis Lee Bieber wrote:
> On Sat, 25 Aug 2012 14:47:35 -0600, "Littlefield, Tyler"
> <tyler@tysdomain.com> 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.
>
>


-- 
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: modeling complex data with sqlalchemy "Littlefield, Tyler" <tyler@tysdomain.com> - 2012-08-26 10:38 -0600

csiph-web