mirror of
https://github.com/RPG-Research/bcirpg.git
synced 2024-04-16 14:23:01 +00:00
2.3 KiB
2.3 KiB
-
Table: Items
- This table will store information about base items like powerups.
CREATE TABLE items ( item_id serial PRIMARY KEY, name VARCHAR(255) NOT NULL );
-
Table: Synonyms
- This table will store synonyms for each item, referencing the
items
table.
CREATE TABLE synonyms ( synonym_id serial PRIMARY KEY, item_id INT REFERENCES items(item_id), synonym VARCHAR(255) NOT NULL );
- This table will store synonyms for each item, referencing the
-
Table: Genres
- This table will store different genres, like "fantasy" or "modern day."
CREATE TABLE genres ( genre_id serial PRIMARY KEY, name VARCHAR(255) NOT NULL );
-
Table: Items_Genres
- This table will establish a many-to-many relationship between items and genres, as an item can belong to multiple genres.
CREATE TABLE items_genres ( item_id INT REFERENCES items(item_id), genre_id INT REFERENCES genres(genre_id), PRIMARY KEY (item_id, genre_id) );
With this schema, you can:
- Add base items like powerups to the
items
table. - Associate synonyms for each base item in the
synonyms
table, referencing the corresponding item. - Categorize base items into different genres in the
genres
table. - Establish relationships between base items and genres in the
items_genres
table.
Here's an example of how you might use this schema:
-- Insert a base item
INSERT INTO items (name) VALUES ('Health Potion');
-- Insert synonyms for the base item
INSERT INTO synonyms (item_id, synonym) VALUES (1, 'Health Potion');
INSERT INTO synonyms (item_id, synonym) VALUES (1, 'Stimpack');
-- Insert genres
INSERT INTO genres (name) VALUES ('Fantasy');
INSERT INTO genres (name) VALUES ('Modern Day');
-- Associate the base item with genres
INSERT INTO items_genres (item_id, genre_id) VALUES (1, 1); -- Health Potion belongs to Fantasy
INSERT INTO items_genres (item_id, genre_id) VALUES (1, 2); -- Health Potion also belongs to Modern Day
-- Select the Fantasy name of an the heavy armor base item that you are looking for.
SELECT genres.name
FROM genres
JOIN items_genres ON genres.genre_id = items_genres.genre_id
JOIN base_items ON items_genres.base_item_id = base_items.item_id
WHERE base_items.name = 'heavy armor'
AND genres.name = 'Fantasy';