|
Posted by Neo on 08/15/07 21:59
> a simple way to do database schema design.
> user can type in the movie name and zipcode,
> return all the theaters showing that movie
> and at what time, for theaters in THAT zipcode.
Below is how one could do it using dbd, a lightweight, memory-resident
database. Unlike RMDBs that store values in table-like structures, dbd
stores data as a network of nodes where each node is equivalent to an
AND gate. Below script enters sample data and runs desired query:
(; Create movies)
(new 'underdog 'movie)
(new 'cars 'movie)
(new 'superman 'movie)
(new 'alien 'movie)
(; Create theatres)
(new 'amc1 'theatre)
(new 'amc2 'theatre)
(new 'amc3 'theatre)
(new 'cinemark1 'theatre)
(new 'cinemark2 'theatre)
(new 'cinemark3 'theatre)
(; Create zipcodes)
(new '22222 'zipcode)
(new '33333 'zipcode)
(; Create movie times)
(new '1700 'time)
(new '1900 'time)
(new '2100 'time)
(; Set threatre zipcodes)
(set amc1 zipcode 22222)
(set amc2 zipcode 33333)
(set amc3 zipcode 33333)
(set cinemark1 zipcode 22222)
(set cinemark2 zipcode 22222)
(set cinemark3 zipcode 33333)
(new 'shows 'verb)
(set amc1 shows underdog at 1700)
(set amc1 shows underdog at 2100)
(set amc1 shows superman at 1900)
(set amc1 shows superman at 2100)
(set amc2 shows cars at 1900)
(set amc2 shows cars at 2100)
(set amc2 shows alien at 1900)
(set amc2 shows alien at 2100)
(set amc3 shows underdog at 1900)
(set amc3 shows alien at 2100)
(set cinemark1 shows cars at 1700)
(set cinemark1 shows cars at 2100)
(set cinemark1 shows alien at 1900)
(set cinemark1 shows alien at 2100)
(set cinemark2 shows superman at 1700)
(set cinemark2 shows superman at 2100)
(set cinemark2 shows cars at 1900)
(set cinemark2 shows cars at 2100)
(set cinemark3 shows underdog at 2100)
(set cinemark3 shows superman at 2100)
(; Get all theatres/times in zip 33333 that shows alien)
(; Following query gets following 3 nodes:
amc2 shows alien at 1900
amc2 shows alien at 2100
amc3 shows alien at 2100)
(get (get * zipcode 33333)
shows alien at (get time instance *))
For more info, see www.dbfordummies.com
Navigation:
[Reply to this message]
|