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


Groups > comp.lang.python > #27891 > unrolled thread

Re: modeling complex data with sqlalchemy

Started byDennis Lee Bieber <wlfraed@ix.netcom.com>
First post2012-08-25 19:53 -0400
Last post2012-08-25 19:53 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: modeling complex data with sqlalchemy Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-25 19:53 -0400

#27891 — Re: modeling complex data with sqlalchemy

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-08-25 19:53 -0400
SubjectRe: modeling complex data with sqlalchemy
Message-ID<mailman.3819.1345938798.4697.python-list@python.org>
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.


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web